Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw error if @Group key is missing #372

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

tanner0101
Copy link
Member

@tanner0101 tanner0101 commented Aug 5, 2020

Fixes an issue causing @Group to silently ignore missing data when decoding (#372).

@Group will now throw an error if required data is missing while decoding. This prevents force unwrap issues due to accessing uninitialized values.

Note: It is recommended that you use DTOs to encode/decode your models from your API. Read more here: https://docs.vapor.codes/4.0/fluent/model/#data-transfer-object

@tanner0101 tanner0101 added the bug Something isn't working label Aug 5, 2020
@tanner0101 tanner0101 added this to Awaiting Review in Vapor 4 via automation Aug 5, 2020
@tanner0101 tanner0101 added the semver-patch Internal changes only label Aug 5, 2020
gwynne
gwynne previously requested changes Oct 30, 2020
Sources/FluentKit/Model/Fields+Codable.swift Outdated Show resolved Hide resolved
Sources/FluentKit/Model/Fields+Codable.swift Outdated Show resolved Hide resolved
Sources/FluentKit/Model/Fields+Codable.swift Outdated Show resolved Hide resolved
Sources/FluentKit/Properties/Parent.swift Outdated Show resolved Hide resolved
Base automatically changed from master to main March 12, 2021 02:50
@gwynne
Copy link
Member

gwynne commented Nov 20, 2021

This is technically semver-patch, but the change in behavior of thrown decoding errors could easily break existing error recovery logic, especially given how long this has been broken. Also people may be relying on the "ignores missing keys" behavior by now. Is it worth it to merge this?

@0xTim
Copy link
Member

0xTim commented Nov 20, 2021

I think it's worth adding. If anyone retrieves the group and then tries to access the property it's gonna fail right?

@gwynne
Copy link
Member

gwynne commented Nov 20, 2021

I'm actually not sure if you would hit the fatalError() path that way as things stand... if so then it's not a breaking change.

@Joannis
Copy link
Member

Joannis commented Nov 21, 2021

@gwynne from my experience with fluent-mongo, I believe I ran into fatalError() here.

@Joannis
Copy link
Member

Joannis commented Nov 21, 2021

Can be easily tested there

Comment on lines +20 to +21
// This assertion's validity changes between Swift versions.
//XCTAssertEqual(ObjectIdentifier(type), ObjectIdentifier([String: Any].self), "\(type) != \([String: Any].self)")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably need to rewrite the test or find another way. At the very least the commented out code should go

@Joannis Joannis removed their request for review August 12, 2023 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working semver-patch Internal changes only
Projects
Vapor 4
  
Awaiting Review
Development

Successfully merging this pull request may close these issues.

None yet

4 participants