Skip to content

bdb/dont-run-null-properties-through-converters#43

Merged
bbotto-pdga merged 6 commits intodevelopfrom
bdb/dont-run-null-properties-through-converters
Sep 20, 2023
Merged

bdb/dont-run-null-properties-through-converters#43
bbotto-pdga merged 6 commits intodevelopfrom
bdb/dont-run-null-properties-through-converters

Conversation

@bbotto-pdga
Copy link
Copy Markdown

I made this change because of a bug I found during this morning's API meeting. In a nutshell, NULL values from the database get converted using Converter classes. For example, a NULL value in a DATETIME column gets converted on retrieve by the DateTimeConverter, 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 passing null values to converters. The downside of this approach is that we can't convert null values, but I don't think we would ever want to convert null values in columns. The alternative would be to check for null in each Converter.

Copy link
Copy Markdown
Member

@pcrist pcrist left a comment

Choose a reason for hiding this comment

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

Looks good!

}

return $column->getConverter()->onSave($property);
return $property === null
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You mentioned DATETIME columns. Do we care about testing that column type specifically?

@bbotto-pdga bbotto-pdga merged commit 3d1c52b into develop Sep 20, 2023
@bbotto-pdga bbotto-pdga deleted the bdb/dont-run-null-properties-through-converters branch September 20, 2023 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants