ENG-3828: Fix Pydantic serializer warning for AnyHttpUrlStringRemovesSlash#8193
Merged
Conversation
The annotation declared `AnyHttpUrl` but `AfterValidator` returned a `str`, causing `PydanticSerializationUnexpectedValue` warnings whenever fields of this type were serialized with a populated value. Most call sites were unaffected because their values were typically `None`, but `url_recorded` on the privacy-preference celery payload (set from the HTTP referer header) consistently triggered the warning. Attach a `PlainSerializer` so the serializer expects `str` to match what the validator actually produces.
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
erosselli
approved these changes
May 14, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8193 +/- ##
=======================================
Coverage 85.59% 85.59%
=======================================
Files 658 658
Lines 42847 42847
Branches 5018 5018
=======================================
+ Hits 36675 36676 +1
Misses 5064 5064
+ Partials 1108 1107 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Ticket https://ethyca.atlassian.net/browse/ENG-3828
Description Of Changes
AnyHttpUrlStringRemovesSlashwas declared asAnnotated[AnyHttpUrl, AfterValidator(...)], but theAfterValidatorreturns a plainstr. At serialization time Pydantic still expected anAnyHttpUrlinstance and emitted aPydanticSerializationUnexpectedValuewarning whenever the field held a real value.Concretely surfaced in the celery task
Saving record(s) of current preferences and historical preferences for consent reportingafter ENG-2488 switchedurl_recordedfromSafeStrtoAnyHttpUrlStringRemovesSlash:Attach a
PlainSerializer(return_type=str)so the serializer type matches what the validator actually produces. No behavioral change to the output value (stillstrwith trailing slash stripped), but the warning is gone and the field now round-trips cleanly.Code Changes
src/fides/api/custom_types.py— addedPlainSerializertoAnyHttpUrlStringRemovesSlash.tests/lib/test_custom_types.py— newTestAnyHttpUrlStringRemovesSlashcovering validation, trailing-slash stripping, invalid-URL rejection,Nonepassthrough, and a regression test that promotes the serializer warning to an error.Steps to Confirm
nox -s "pytest(lib)"(ordocker exec fides /opt/fides/bin/python -m pytest tests/lib/test_custom_types.py) — all 208 tests pass, including the 11 new ones.custom_types.pychange and re-runTestAnyHttpUrlStringRemovesSlash::test_serialization_does_not_warn— it fails with the exactPydanticSerializationUnexpectedValuewarning quoted above.url_recorded— the warning no longer appears in worker logs.Pre-Merge Checklist
CHANGELOG.mdupdated (follow-up commit on this PR)