Skip to content

fix(labels): handle missing metadata and fix add_labels serialization#59

Open
geopanther wants to merge 1 commit into
mainfrom
fix/label-edge-cases
Open

fix(labels): handle missing metadata and fix add_labels serialization#59
geopanther wants to merge 1 commit into
mainfrom
fix/label-edge-cases

Conversation

@geopanther

Copy link
Copy Markdown
Owner

Summary

Fix two label-related edge cases that cause crashes on some Confluence server versions.

Adapted from iamjackg/md2cf#118 by @nate-woythaler.

Changes

  1. add_labels(): Changed from data= (form-encoded) to json= for proper JSON serialization of label payloads
  2. labels_need_updating(): Added defensive getattr chain to handle pages without metadata.labels.results — treats missing metadata as 'needs update'

Differences from upstream

  • Upstream changed labels_need_updating() to use dict-style .get() access, which breaks the existing Bunch-based object model. We use getattr chains instead, preserving compatibility with the Bunch response objects
  • Upstream's json.dumps() wrapper for update_page labels is unnecessary since requests handles JSON serialization via the json= parameter — omitted
  • Removed dead # return self.api.content(page.id).post( comment

Tests

  • New test: test_labels_need_updating_when_no_metadata
  • All 17 upsert tests pass

Fix two label-related edge cases:
1. add_labels() used data= (form-encoded) instead of json= for
   the label payload, causing failures on some Confluence versions
2. labels_need_updating() crashed with AttributeError when page
   metadata.labels.results was absent (e.g., new pages without labels)

Adapted from iamjackg/md2cf#118 by @nate-woythaler.
@geopanther

Copy link
Copy Markdown
Owner Author

Maintainer Review

Verdict: ✅ Approve

Both fixes address real bugs that would hit users of self-hosted Confluence or pages created before labels were supported.

add_labels fix: Using data= with a list of dicts sends form-encoded data, which Confluence can't parse as JSON. Switching to json= is correct and matches how update_page already sends label data.

labels_need_updating fix: The triple-getattr chain is defensive but appropriate — we can't control what the Confluence API returns, and missing metadata is a documented issue on older versions. Treating missing metadata as 'needs update' is the safe default.

vs upstream: Our approach is cleaner — upstream switched to dict-style access (.get()) which is inconsistent with the Bunch-based object model used everywhere else. We preserve the object-attribute access pattern.

No concerns. Ship it.

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.

1 participant