WIP: Tolerate Unknown Fields in Responses#1425
Open
genematx wants to merge 5 commits into
Open
Conversation
Extract the `python-tiled/<version>` User-Agent parsing that was open-coded in `about`, `_model_dump_backcompat`, and `client_compatibility_check` into a new `tiled/server/_backcompat.py` module. `raw_python_tiled_client_version` returns the version string (or None if the client is not python-tiled) and `parse_python_tiled_client_version` returns a parsed `packaging.version.Version` (or None if absent/unparseable). No behavior change.
The `size` field was added to `tiled.structures.data_source.Asset` in v0.2.13. Older python-tiled clients unpack the JSON payload directly as dataclass kwargs in `DataSource.from_json`, so they crash with `Asset.__init__() got an unexpected keyword argument 'size'` when talking to a current server. Mirror the existing pre-0.2.4 `properties` back-compat: sniff the `python-tiled/<version>` User-Agent and drop `size` from asset payloads on both the GET metadata path (`_model_dump_backcompat`) and the POST metadata response path. Non-python-tiled clients are unaffected.
The helper assumed `response["data"]` was always a dict of a single resource (as in GET metadata), but search responses shape it as a list of resources. Normalize to iterate resources uniformly and collect data_sources from all of them before stripping.
20d8537 to
d6bd226
Compare
When a client built against an older Tiled release talks to a newer server that has added a field to a client-side dataclass (Asset, DataSource, Spec, AwkwardStructure, TableStructure, ContainerStructure, ...), the client previously crashed with `TypeError: unexpected keyword argument` because `Structure.from_json`, `DataSource.from_json`, and `Spec(**...)` splatted the payload directly into the dataclass. Add a small `filter_known_kwargs` helper in `tiled.structures._compat` that drops unknown keys and logs them at DEBUG. Wire it into `Structure.from_json`, `Asset.from_json` (new), `DataSource.from_json`, and `Spec.from_json` (new), and update the two `Spec(**spec)` call sites in `tiled.client.base` to use `Spec.from_json`. The server continues to strip fields for known-broken client versions via the User-Agent gate, but this makes the client resilient to any future additions without requiring a server-side back-compat entry.
d6bd226 to
87cec1d
Compare
danielballan
approved these changes
Jul 8, 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.
Tolerate unknown fields on the client side when decoding server JSON into
Asset,DataSource,Spec, and structure dataclasses (AwkwardStructure,TableStructure,ContainerStructure). Unknown keys are dropped and logged at DEBUG so a client can talk to a newer server without crashing on fields it does not recognize.Related Issue: #1426
Checklist
Add the ticket number which this PR closes to the comment section