Skip to content

WIP: Tolerate Unknown Fields in Responses#1425

Open
genematx wants to merge 5 commits into
bluesky:mainfrom
genematx:tolerate-unknown-server-fields
Open

WIP: Tolerate Unknown Fields in Responses#1425
genematx wants to merge 5 commits into
bluesky:mainfrom
genematx:tolerate-unknown-server-fields

Conversation

@genematx

@genematx genematx commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

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 a Changelog entry
  • Add the ticket number which this PR closes to the comment section

genematx added 4 commits July 8, 2026 14:04
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.
@genematx genematx force-pushed the tolerate-unknown-server-fields branch 2 times, most recently from 20d8537 to d6bd226 Compare July 8, 2026 18:47
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.
@genematx genematx force-pushed the tolerate-unknown-server-fields branch from d6bd226 to 87cec1d Compare July 8, 2026 19:03
@genematx genematx requested a review from danielballan July 8, 2026 19:05
@genematx genematx marked this pull request as ready for review July 8, 2026 19:05
@genematx genematx changed the title Tolerate unknown server fields Tolerate Unknown Fields in Responses Jul 8, 2026
@genematx genematx changed the title Tolerate Unknown Fields in Responses WIP: Tolerate Unknown Fields in Responses Jul 8, 2026
Sign up for free to 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.

2 participants