Skip to content

Preserve reco fields through to_dict and from_dict round trips - #3383

Open
adamtheturtle wants to merge 1 commit into
mainfrom
adamtheturtle/vws-python-mock-issue-3374
Open

Preserve reco fields through to_dict and from_dict round trips#3383
adamtheturtle wants to merge 1 commit into
mainfrom
adamtheturtle/vws-python-mock-issue-3374

Conversation

@adamtheturtle

Copy link
Copy Markdown
Member

CloudDatabase.to_dict omitted reco_threshold, total_recos, current_month_recos and previous_month_recos, and ImageTarget.to_dict omitted the three reco counts plus reco_rating, so from_dict restored those fields to their class defaults. This is invisible today because those fields are always at their defaults, but it would silently reset seeded reco counts in the Docker backend, which round-trips every database through to_dict/from_dict on every request.

These fields are now added to CloudDatabaseDict, ImageTargetDict and both to_dict/from_dict pairs, as NotRequired keys with the dataclass defaults so existing dictionaries still load. New round-trip tests build a CloudDatabase and an ImageTarget with every field set to a non-default value, assert from_dict(to_dict(x)) == x, and assert the dataclass field names against an explicit set so that a newly added field cannot quietly fall out of the serialisation.

The ImageTarget rater identity is still deliberately not preserved; the test asserts the computed tracking_rating survives instead.

Fixes#3374.

🤖 Generated with Claude Code

``CloudDatabase.to_dict`` omitted ``reco_threshold``, ``total_recos``,
``current_month_recos`` and ``previous_month_recos``, and
``ImageTarget.to_dict`` omitted the three reco counts plus
``reco_rating``, so ``from_dict`` restored those fields to their class
defaults.
Add round trip tests which assert that every field of both dataclasses
survives, so that a new field cannot quietly fall out of the
serialisation.
Fixes#3374.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@adamtheturtle
adamtheturtleforce-pushed the adamtheturtle/vws-python-mock-issue-3374 branch from 5108c77 to 597b989CompareAugust 9, 2026 21:24
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

to_dict and from_dict silently drop the reco count fields

1 participant

@adamtheturtle