Skip to content

fix(backend): @field_serializer für BatchRead.created_at ergänzt (UTC/Z-Suffix)#97

Merged
strausmann merged 1 commit into
mainfrom
fix/batch-job-datetime-utc-serializer
Jun 2, 2026
Merged

fix(backend): @field_serializer für BatchRead.created_at ergänzt (UTC/Z-Suffix)#97
strausmann merged 1 commit into
mainfrom
fix/batch-job-datetime-utc-serializer

Conversation

@strausmann

Copy link
Copy Markdown
Owner

Summary

BatchRead.created_at wurde bisher als naiver ISO-String ohne Zeitzonen-Suffix
serialisiert (2026-06-02T09:46:18.701971). Der Go-RFC3339-Parser im Hangar-Client
(Phase 1d) erwartet einen TZ-Offset und lehnte das Format ab:

decode batch snapshot: parsing time "2026-06-02T09:46:18.701971"
as "2006-01-02T15:04:05Z07:00": cannot parse "" as "Z07:00"

Folge: Hangar zeigte „Hub aktuell nicht erreichbar — Status nicht verfügbar."
obwohl der Hub erreichbar war und valide Daten lieferte.

Fix: @field_serializer("created_at") mit dem bestehenden serialize_datetime_utc
Helper ergänzt — analog zu TemplateRead und JobRead, die bereits korrekt
serialisieren. JobRead war nicht betroffen (hatte bereits alle Serializer).

Contributor License Agreement (CLA)

By opening this pull request you affirm that you have read and agree to the
project's Contributor License Agreement for the contribution(s)
included here.

Linked issue

Type of change

  • Bug fix (non-breaking)

Hardware tested on

  • No hardware impact

Test coverage

  • Added/updated unit tests
  • Existing tests still pass

Neue Datei: backend/tests/unit/schemas/test_batch_read.py (7 Tests, TDD RED→GREEN)

  • test_created_at_naive_serialised_with_z_suffix — Hauptregression
  • test_created_at_utc_aware_serialised_with_z_suffix — UTC-aware Pfad
  • test_created_at_no_naive_iso_without_tz — kein naiver String ohne Suffix
  • test_batch_read_full_json_contains_z_timestamps — Vollständiger JSON-Roundtrip
  • BatchSummary.all_terminal Logik

Checklist

  • PR title follows Conventional Commits (feat(...): ... etc.)
  • CHANGELOG entry isn't needed (semantic-release generates it)
  • Documentation updated (if behaviour, API, or config changed)
  • No private IPs, hostnames, domains, real tokens, or PII in commits
  • CI is green (will be checked again after CI runs)

Migration / breaking change notes

Keine. Die Serialisierung von created_at war bisher fehlerhaft (naive ISO
ohne TZ). Das neue Format (...Z) ist das korrekte RFC3339-Format und repariert
bestehende Clients, die RFC3339 strict parsen.

Screenshots / output

Vorher (Regression):

"created_at": "2026-06-02T09:46:18.701971"

Nachher (Fix):

"created_at": "2026-06-02T09:46:18.701971Z"

…/Z-Suffix)

BatchRead lieferte created_at als naiven ISO-String ohne TZ-Suffix
(`2026-06-02T09:46:18.701971`). Der Go-RFC3339-Parser im Hangar-Client
lehnte das ab: `cannot parse "" as "Z07:00"`. Folge: Hangar zeigte
"Hub aktuell nicht erreichbar" obwohl der Hub erreichbar war.

Fix: @field_serializer("created_at") mit serialize_datetime_utc analog
zu TemplateRead und JobRead. Tests in
tests/unit/schemas/test_batch_read.py (RED→GREEN, TDD).
Copilot AI review requested due to automatic review settings June 2, 2026 09:53
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Dieser Pull Request behebt einen Serialisierungsfehler in der 'BatchRead'-Schema-Definition. Bisher wurden Zeitstempel als naive ISO-Strings ohne Zeitzonen-Suffix ausgegeben, was zu Fehlern beim Parsen durch den Go-basierten Hangar-Client führte. Durch die Verwendung eines bestehenden Serialisierungs-Helpers wird nun sichergestellt, dass alle Zeitstempel ein korrektes 'Z'-Suffix erhalten, was die Interoperabilität zwischen Backend und Client sicherstellt.

Highlights

  • Serialisierungs-Fix: Das Feld 'created_at' in 'BatchRead' wurde um einen '@field_serializer' ergänzt, um sicherzustellen, dass Zeitstempel im korrekten RFC3339-Format mit 'Z'-Suffix serialisiert werden.
  • Kompatibilität: Durch die Korrektur der Zeitstempel-Serialisierung wird die Kompatibilität mit dem Go-Client des Hangar-Systems wiederhergestellt, der striktes RFC3339-Parsing erfordert.
  • Testabdeckung: Es wurden umfassende Unit-Tests in 'backend/tests/unit/schemas/test_batch_read.py' hinzugefügt, die verschiedene Szenarien für naive und UTC-aware Zeitstempel abdecken.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a custom field serializer for the created_at field in BatchRead to ensure datetime values are serialized with a UTC timezone offset, preventing decoding issues with Go's strict RFC3339 parser. It also adds unit tests to verify this serialization behavior and test BatchSummary terminal logic. The review feedback suggests improving the test assertions by using datetime.datetime.fromisoformat() to validate the presence of timezone information instead of performing manual string slicing.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +104 to +109
created_at_str: str = dumped["created_at"]
# Muss entweder mit Z oder +HH:MM enden — nie mit einer reinen Zeitangabe
has_tz = created_at_str.endswith("Z") or (
len(created_at_str) >= 6 and created_at_str[-6] in ("+", "-")
)
assert has_tz, f"Kein TZ-Suffix in created_at: {created_at_str!r}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Anstatt den String manuell zu parsen und auf Suffixe wie Z oder +/- an bestimmten Positionen zu prüfen, kann die Zeitzonen-Validierung robuster und eleganter über datetime.datetime.fromisoformat() gelöst werden. Wenn das Ergebnis ein tzinfo besitzt, ist eine Zeitzone vorhanden.

    created_at_str: str = dumped["created_at"]
    parsed_dt = datetime.datetime.fromisoformat(created_at_str)
    assert parsed_dt.tzinfo is not None, f"Kein TZ-Suffix in created_at: {created_at_str!r}"

Comment on lines +127 to +130
val: str = data[field]
assert "Z" in val or "+" in val or (len(val) >= 6 and val[-6] == "-"), (
f"Feld {field!r} hat keinen TZ-Suffix: {val!r}"
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Auch hier lässt sich die Zeitzonen-Validierung robuster über datetime.datetime.fromisoformat() abbilden, um manuelle String-Slicing-Prüfungen zu vermeiden.

        val: str = data[field]
        parsed_dt = datetime.datetime.fromisoformat(val)
        assert parsed_dt.tzinfo is not None, f"Feld {field!r} hat keinen TZ-Suffix: {val!r}"

@codecov

codecov Bot commented Jun 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.90%. Comparing base (32cd93e) to head (c319902).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #97      +/-   ##
==========================================
+ Coverage   89.84%   89.90%   +0.05%     
==========================================
  Files          89       89              
  Lines        4019     4023       +4     
  Branches      345      345              
==========================================
+ Hits         3611     3617       +6     
+ Misses        318      317       -1     
+ Partials       90       89       -1     
Components Coverage Δ
Printer Backends (transport) 87.50% <ø> (ø)
Printer Models (drivers) 91.42% <ø> (ø)
Services 91.23% <ø> (+0.30%) ⬆️
REST API 85.08% <ø> (ø)
Pydantic Schemas 100.00% <100.00%> (ø)
Integration Plugins 100.00% <ø> (ø)
Files with missing lines Coverage Δ
backend/app/schemas/batch_read.py 100.00% <100.00%> (ø)

... and 2 files with indirect coverage changes

Flag Coverage Δ
backend 89.90% <100.00%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ba1e4f6...c319902. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@strausmann
strausmann merged commit eb2132c into main Jun 2, 2026
20 checks passed
@strausmann
strausmann deleted the fix/batch-job-datetime-utc-serializer branch June 2, 2026 09:56

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes RFC3339-Strict Kompatibilität für den Hangar-Go-Client, indem BatchRead.created_at jetzt konsistent als UTC-Zeitstempel mit Z-Suffix serialisiert wird (statt naivem ISO-String ohne TZ).

Changes:

  • Ergänzt @field_serializer("created_at") in BatchRead, der den bestehenden serialize_datetime_utc-Helper nutzt.
  • Fügt Unit-Tests hinzu, die das Z-Suffix für naive und UTC-aware created_at validieren sowie BatchSummary.all_terminal abdecken.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
backend/app/schemas/batch_read.py Ergänzt Serializer für created_at über serialize_datetime_utc, um RFC3339 (...Z) sicherzustellen.
backend/tests/unit/schemas/test_batch_read.py Neue Unit-Tests für BatchRead.created_at-Serialisierung und BatchSummary.all_terminal.

Comment on lines +125 to +130
# Alle datetime-Felder auf oberster Ebene prüfen
for field in ("created_at",):
val: str = data[field]
assert "Z" in val or "+" in val or (len(val) >= 6 and val[-6] == "-"), (
f"Feld {field!r} hat keinen TZ-Suffix: {val!r}"
)
github-actions Bot pushed a commit that referenced this pull request Jun 3, 2026
## <small>0.8.2 (2026-06-03)</small>

* fix(backend): BatchRead datetime UTC-Serializer für Hangar-Decode (#97) ([eb2132c](eb2132c)), closes [#97](#97)

[skip ci]
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