bdb/dont-run-null-properties-through-converters#43
Merged
bbotto-pdga merged 6 commits intodevelopfrom Sep 20, 2023
Merged
Conversation
pcrist
approved these changes
Sep 12, 2023
src/Models/ModelInstantiator.php
Outdated
| } | ||
|
|
||
| return $column->getConverter()->onSave($property); | ||
| return $property === null |
Member
There was a problem hiding this comment.
Minor style note: This is terse and readable, so no change is needed, but my instinct would be to have the null check as a separate conditional with a commented explanation (e.g. "Null values are not converted... etc"), like the conditional on line 351.
Anyway, I don't necessarily see these methods growing with age, so it's fine to be concise.
| // Privacy uses the yes/no converter, but it's null so it shouldn't be | ||
| // converted. | ||
| $data_object = new ModelInstantiatorTestObject(); | ||
| $data_object->privacy = null; |
Member
There was a problem hiding this comment.
You mentioned DATETIME columns. Do we care about testing that column type specifically?
drew-acheson
approved these changes
Sep 12, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I made this change because of a bug I found during this morning's API meeting. In a nutshell,
NULLvalues from the database get converted usingConverterclasses. For example, aNULLvalue in aDATETIMEcolumn gets converted on retrieve by theDateTimeConverter, and the result is the current time. That's a bug.Since converters only run on
Column-attributed properties, I think this is the correct way to fix this issue--namely, not passingnullvalues to converters. The downside of this approach is that we can't convertnullvalues, but I don't think we would ever want to convertnullvalues in columns. The alternative would be to check fornullin eachConverter.