-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Serializer] Deprecate using datetime construct as fallback on default format mismatch #47095
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
[Serializer] Deprecate using datetime construct as fallback on default format mismatch #47095
Conversation
(rebase unlocked) |
88c8ff8
to
55be0a1
Compare
src/Symfony/Component/Serializer/Tests/Normalizer/DateTimeNormalizerTest.php
Show resolved
Hide resolved
@@ -113,6 +113,8 @@ public function denormalize(mixed $data, string $type, string $format = null, ar | |||
if (false !== $object) { | |||
return $object; | |||
} | |||
|
|||
trigger_deprecation('symfony/serializer', '6.2', 'Relying on a datetime constructor as a fallback when using a specific default date format (`datetime_format`) for the DateTimeNormalizer is deprecated. Respect the "%s" default format.', $defaultDateTimeFormat); |
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.
What will the code look like in 7.0? Can we add a hint as a comment here?
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.
Depending on how we answer the questions in PR description, In 7.0, the fallback path will be either totally removed or disabled by default.
trigger_deprecation('symfony/serializer', '6.2', 'Relying on a datetime constructor as a fallback when using a specific default date format (`datetime_format`) for the DateTimeNormalizer is deprecated. Respect the "%s" default format.', $defaultDateTimeFormat); | |
trigger_deprecation('symfony/serializer', '6.2', 'Relying on a datetime constructor as a fallback when using a specific default date format (`datetime_format`) for the DateTimeNormalizer is deprecated and will be removed in 7.0. Respect the "%s" default format.', $defaultDateTimeFormat); |
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.
I'd got with 3 when format is auto
.
3752548
to
8937432
Compare
PR updated to add the |
8937432
to
8bcd45b
Compare
8bcd45b
to
41a1d56
Compare
This didn't get traction so I guess this isn't much desired. On my side at least I don't see why this would be an improvement. I'd prefer closing. |
I think I agree with @nicolas-grekas here. |
This PR is a follow-up to #43329 and aims to enforce the configured default format is always respected, instead of silently fallback to the
\DateTime
&\DateTimeImmutable
constructors.As of today, the only way to enforce this format is to set it locally through the context.
For now, the PR just adds the deprecation in case the fallback path is reached. One could argue this might be enough, since not respecting the expected format as an end user of an API might be considered as an issue in the first place.
Still:
Do we need a better upgrade path?
e.g:
\DateTimeNormalizer::USE_DATETIME_CONSTRUCT_AS_FALLBACK => false,
and trigger a deprec if this flag is not set. Default 6.2:
true
, 7.0:false
Do we want to keep the ability to use the datetime constructs as fallbacks?
e.g:
\DateTimeNormalizer::USE_DATETIME_CONSTRUCT_AS_FALLBACK => false,
Then, this behavior should be consistent whenever a default format or a context one is used (there is no fallback right now if set from the context)
Do we want to keep the datetime constructs call whenever the default format is
null
?Then, one should be able to "unset" the default format by passing in the context:
(currently fallbacks to the default format) or use a special value to do so (
php-datetime-string
?).