Skip to content

[Serializer] Trigger deprecation when could not parse date with default format #58966

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

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

Conversation

alexndlm
Copy link
Contributor

Q A
Branch? 7.3
Bug fix? no
New feature? no
Deprecations? yes
Issues
License MIT

Relates to #43329 (comment)

@alexndlm
Copy link
Contributor Author

@nicolas-grekas Could you have a look?

Copy link
Contributor

@mtarld mtarld left a comment

Choose a reason for hiding this comment

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

Could you update the Serializer's CHANGELOG.md file and the UPGRADE-7.3.md file as well?

@mtarld
Copy link
Contributor

mtarld commented Jan 13, 2025

Looks like the tests must be updated to not trigger the deprecation.

@@ -126,6 +126,8 @@ public function denormalize(mixed $data, string $type, ?string $format = null, a
if (false !== $object = $type::createFromFormat($defaultDateTimeFormat, $data, $timezone)) {
return $object;
}

trigger_deprecation('symfony/serializer', '7.3', \sprintf('A "%s" will be thrown when a date could not be parsed using the default format "%s".', NotNormalizableValueException::class, $defaultDateTimeFormat));
Copy link
Member

Choose a reason for hiding this comment

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

I think we should trigger a deprecation here only if the fallback manages to instantiate it. The case where the fallback throws an exception (already turned into a NotNormalizableValueException below) should not trigger a deprecation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I understand, in 8.0, the fallback should be removed, right?

Copy link
Member

Choose a reason for hiding this comment

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

yes. And that's my point: if the fallback also fails, you already have the same behavior than what would happen in 8.0 and we should not trigger a deprecation in that case as the behavior will not change. Try submitting foobar as value to reproduce that case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have rechecked and now realise that fallback should not be removed in 8.0. Fallback should still be used when datetime_format is set to null.

@alexndlm alexndlm force-pushed the feature/serializer-trigger-deprecation-when-could-not-parse-date-with-default-format branch from 66a1ede to 663eec5 Compare January 13, 2025 17:26
@alexndlm
Copy link
Contributor Author

@mtarld I have done with your comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants