Skip to content

Keep explicitly null to-one relationships as present-with-null - #50

Merged
shime merged 2 commits into
mainfrom
fix/null-to-one-relationships-read-as-nil
Jul 16, 2026
Merged

Keep explicitly null to-one relationships as present-with-null#50
shime merged 2 commits into
mainfrom
fix/null-to-one-relationships-read-as-nil

Conversation

@shime

@shime shime commented Jul 15, 2026

Copy link
Copy Markdown
Member

booqable 2.0's strict attribute reads treat "present with a null value" as nil and only raise Booqable::MissingAttribute for keys absent from the payload. But the JSON:API serializer drops a to-one relationship serialized with "data": null from the parsed resource entirely, so it reads as absent and raises.

That breaks real, everyday payloads in the apps — found while merging booqable 2.0 into logistics' weights PR (logistics#26):

  • an order's charge lines (e.g. a delivery-rate line) serialize "item": {"data": null}line.item raises instead of returning nil
  • a product without a barcode serializes "barcode": {"data": null}item.barcode raises

A null relationship is present-with-null — the line has no item — exactly like a null attribute, so the parser now keeps the key and sets it to nil. To-many relationships are unaffected (data is always an array), and absent relationships still raise as designed.

🤖 Generated with Claude Code


Open in Devin Review

The JSON:API serializer dropped a to-one relationship serialized with
"data": null from the parsed resource entirely, so strict reads raised
Booqable::MissingAttribute — but a null relationship is present-with-null
(the order line HAS no item), exactly like a null attribute, which the
StrictAttributes contract says reads as nil. Keep the key, set it to nil.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

@devin-ai-integration devin-ai-integration 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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

@shime shime added review Please look at my code team-ow Operations & Workflow labels Jul 16, 2026
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@booqbruno
booqbruno self-requested a review July 16, 2026 12:13
@booqbruno booqbruno removed the review Please look at my code label Jul 16, 2026
@shime
shime merged commit 9f89200 into main Jul 16, 2026
5 checks passed
@shime
shime deleted the fix/null-to-one-relationships-read-as-nil branch July 16, 2026 12:53
@shime shime mentioned this pull request Jul 16, 2026
shime added a commit that referenced this pull request Jul 16, 2026
Included since 2.0.0:

- Add the `app_issues` resource (CRUD for `App::Issue`) (#51)
- Fix: a to-one relationship serialized with `"data": null` (e.g. a
charge line's `item`, or an included `barcode` on a product without one)
now reads as nil, matching the present-with-null attribute semantics —
instead of the parser dropping the key and the read raising
`Booqable::MissingAttribute` (#50)

Originally opened as 2.0.1; renamed to 2.1.0 because #51 adds a resource
(a feature, per the 1.1.0/1.2.0 precedent). The branch name still says
`release/2.0.1` — cosmetic only, the tag comes from `version.rb`.

Unblocks [logistics#26](booqable/logistics#26),
which is temporarily git-pinned to the #50 SHA — once this ships, the
pin swaps back to the published gem.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

team-ow Operations & Workflow

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants