Skip to content

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

Open
ramonski wants to merge 1 commit into
2.xfrom
fix/registry-datetime-serialization
Open

ramonski wants to merge 1 commit into
2.xfrom
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 a commit that referenced this pull request Jul 29, 2026
@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
Base automatically changed from feature/partition-operation to 2.x October 6, 2026 11:20
A registry record holding a datetime made the whole /registry route
answer with a serialization error, because json.dumps has no encoder
for one. The route serializes those values as ISO 8601 strings now,
the way the rest of the API renders a date.

Rewritten against the current 2.x: the registry helpers moved from
api/__init__ to api/settings in #94, after this change was first
written, and the branch still carried the commits of #109, which is
merged. The diff is this change alone.
@ramonski
ramonski force-pushed the fix/registry-datetime-serialization branch from 76ca61f to a2e072a Compare October 7, 2026 05:42
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