-
-
Notifications
You must be signed in to change notification settings - Fork 508
Fix "Document HydratorFactory does not support nullable date field" #2753 #2755
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
base: 2.11.x
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @frenchcomp, thanks for contributing this fix.
Apparently it's breaking an existing test case. Also, the feature needs to be covered by a new non-regression test.
1) Doctrine\ODM\MongoDB\Tests\Functional\DateTest::testDateInstanceValueChangeDoesCauseUpdateIfValueIsTheSame
Failed asserting that an array is not empty.
/home/runner/work/mongodb-odm/mongodb-odm/tests/Doctrine/ODM/MongoDB/Tests/Functional/DateTest.php:102
@@ -185,10 +185,13 @@ private function generateHydratorClass(ClassMetadata $class, string $hydratorCla | |||
<<<'EOF' | |||
|
|||
// Field(type: "date") | |||
if (isset($data['%1$s'])) { | |||
if (isset($data['%1$s']) || (! empty($this->class->fieldMappings['%2$s']['nullable']) && array_key_exists('%1$s', $data))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We avoid usage of empty
as it covers too many cases. Maybe we can refactor the condition like this;
if (isset($data['%1$s']) || (! empty($this->class->fieldMappings['%2$s']['nullable']) && array_key_exists('%1$s', $data))) { | |
if (array_key_exists('%1$s', $data) && ($data['%1$s'] !== null || $this->class->fieldMappings['%2$s']['nullable'] ?? false)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I understand, I had just copied another part of the factory. In an external project I try to maintain consistency.
I forgeted the flag WIP. I just wanted to run the tests, not being able to do it on my machine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, I wasn't aware that empty
is used a lot in this class.
Update code generated by the HydratorFactory for date to support nullable datetime field.
Summary
These PR update only the HydratorFactory class to update the if condition to support nullable field like for other type.
It will update also the clone $return value, because $return can be 'null' and we can not clone null value in PHP.