Fix ItemNormalizer priority conflict intercepting DateTimeImmutable objects#7737
Draft
Fix ItemNormalizer priority conflict intercepting DateTimeImmutable objects#7737
Conversation
Changed all ItemNormalizer variants priority from -890/-895 to -915/-920 to ensure they run AFTER Symfony's DateTimeNormalizer (-910). This prevents ItemNormalizer from incorrectly attempting to normalize DateTimeImmutable objects as API resources. Co-authored-by: soyuka <1321971+soyuka@users.noreply.github.com>
Created functional test to verify DateTimeImmutable objects are correctly normalized by DateTimeNormalizer instead of being incorrectly intercepted by ItemNormalizer. Tests multiple formats (JSON-LD, JSON, HAL, JSON:API). Co-authored-by: soyuka <1321971+soyuka@users.noreply.github.com>
Changed all ItemNormalizer variants to use priority -920 (instead of -915) to ensure they run AFTER all DateTime-related normalizers (-910, -915). This avoids potential priority conflicts where same-priority normalizers have undefined execution order. Added explanatory comment in Laravel config. Co-authored-by: soyuka <1321971+soyuka@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix ItemNormalizer priority conflict with DateTimeImmutable
Fix ItemNormalizer priority conflict intercepting DateTimeImmutable objects
Feb 6, 2026
soyuka
requested changes
Feb 6, 2026
tests/Fixtures/TestBundle/ApiResource/DateTimeNormalizationIssue.php
Outdated
Show resolved
Hide resolved
tests/Fixtures/TestBundle/State/DateTimeNormalizationIssueProvider.php
Outdated
Show resolved
Hide resolved
- Move provider logic to static method inside DateTimeNormalizationIssue fixture - Remove separate DateTimeNormalizationIssueProvider class - Use short class name for provider reference with proper import - Replace regex validation with DateTime::createFromFormat for better date testing Co-authored-by: soyuka <1321971+soyuka@users.noreply.github.com>
soyuka
approved these changes
Feb 6, 2026
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.
Fix ItemNormalizer intercepting DateTimeImmutable before DateTimeNormalizer
Summary:
✅ All changes complete and verified
This PR resolves a critical priority conflict in the Serializer chain where
ItemNormalizervariants were interceptingDateTimeImmutableobjects before Symfony'sDateTimeNormalizercould handle them, causing aLogicException: Can't get a way to read the property "id" in class "DateTimeImmutable".Changes Completed:
Files Changed (8 total):
Configuration (6 files):
src/Symfony/Bundle/Resources/config/api.php- ItemNormalizer: -895 → -920src/Symfony/Bundle/Resources/config/jsonld.php- JsonLdItemNormalizer: -890 → -920src/Symfony/Bundle/Resources/config/hal.php- HalItemNormalizer: -890 → -920src/Symfony/Bundle/Resources/config/jsonapi.php- JsonApiItemNormalizer: -890 → -920src/Symfony/Bundle/Resources/config/graphql.php- GraphQlItemNormalizer: -890 → -920src/Laravel/ApiPlatformProvider.php- All ItemNormalizer variants: -890/-895 → -920Tests (2 files):
tests/Fixtures/TestBundle/ApiResource/DateTimeNormalizationIssue.php- Test resource with static provider methodtests/Functional/DateTimeNormalizerPriorityTest.php- Functional test with proper date validationNormalizer Priority Order (Higher values execute first):
Why -920 specifically?
Using -920 (instead of -915) ensures:
Backward Compatibility:
✅ This change is fully backward compatible. It only affects the internal order in which normalizers are checked. The behavior change is a bug fix - DateTimeImmutable objects will now correctly normalize to ISO 8601 strings instead of throwing exceptions.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.