Skip to content

Fix /registry route failing on datetime registry values - #110

Open
ramonski wants to merge 2 commits into
feature/partition-operationfrom
fix/registry-datetime-serialization
Open

Fix /registry route failing on datetime registry values#110
ramonski wants to merge 2 commits into
feature/partition-operationfrom
fix/registry-datetime-serialization

Conversation

@ramonski

Copy link
Copy Markdown
Contributor

Description of the issue/feature this PR addresses

The /registry route returns the raw registry values straight to the JSON encoder. When a record holds a date or datetime (some default records do), the encoder raises and the whole route fails:

GET @@API/senaite/v1/registry
TypeError: datetime.datetime(2014, 8, 14, 0, 0, 0, 3) is not JSON serializable

get_registry_records_by_keyword now coerces such values (and lists, tuples and dicts containing them) to ISO strings before they reach the encoder. Zope DateTime is handled too.

Current behavior before PR

GET /senaite/v1/registry returns a 500 with a TypeError whenever any registry record holds a date/datetime value.

Desired behavior after PR is merged

Date and datetime registry values are returned as ISO strings, and the route no longer fails. Covered by a new case in api_settings.rst that stores a Datetime record and asserts the record set is JSON serializable.

--
I confirm I have coded it according to PEP8 standards.

ramonski added a commit that referenced this pull request Jul 29, 2026
ramonski added a commit that referenced this pull request Jul 29, 2026
@ramonski
ramonski force-pushed the fix/registry-datetime-serialization branch from 0d69d64 to 6abfb99 Compare July 29, 2026 14:44
@ramonski
ramonski changed the base branch from 2.x to feature/partition-operation July 29, 2026 14:44
ramonski added 2 commits July 29, 2026 17:39
The /registry route returned raw registry values straight to the JSON
encoder, which raised 'datetime.datetime(...) is not JSON serializable'
for records holding a date or datetime. Coerce such values (and containers
of them) to ISO strings before returning, reusing senaite.core.api.dtime
for the datetime and Zope DateTime handling.
@ramonski
ramonski force-pushed the fix/registry-datetime-serialization branch from 6abfb99 to f2cc6d7 Compare July 29, 2026 15:39
@ramonski
ramonski requested a review from xispa July 29, 2026 15:41
@ramonski ramonski added the Bug 🐞 Something is broken label Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug 🐞 Something is broken

Development

Successfully merging this pull request may close these issues.

1 participant