fix: handle missing canprint attribute in Flickr API usage element#91
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Confidence Score: 5/5Safe to merge — the fix is correctly scoped, the upstream The patch is a minimal, targeted workaround for a known upstream bug. The in-place XML mutation happens before the No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant FB as FlickrBot
participant PA as _PatchedFlickrApi
participant FA as FlickrApi (super)
participant Flickr as Flickr HTTP API
FB->>PA: get_single_photo_info(photo_id)
PA->>Flickr: flickr.photos.getInfo
Flickr-->>PA: XML info_resp (usage may be missing attrs)
PA->>PA: parse_single_photo_info(info_resp, photo_id)
Note over PA: find photo/usage element<br/>fill missing candownload/canblog/<br/>canprint/canshare with "0"
PA->>FA: super().parse_single_photo_info(info_resp, photo_id)
FA-->>PA: SinglePhotoInfo dict
PA-->>FB: SinglePhotoInfo dict
Reviews (2): Last reviewed commit: "fix: sort imports in test file" | Re-trigger Greptile |
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Problem
Some Flickr photos return a
<usage>element without thecanprintattribute (and potentially other attributes likecandownload,canblog,canshare). Theflickr-photos-apilibrary (v3.12.1) does a hard dict accessusage_elem.attrib["canprint"]with no fallback, raisingKeyError: 'canprint'. This was caught by the broadexcept Exceptioninget_flickr_photoand logged as:The result was that affected photos only received a bare Flickr photo ID claim, losing all richer metadata (creator, source, date, location).
The
<usage>element is undocumented in the official Flickr API spec — the library added support for it in v3.4 (May 2025) assuming all attributes are always present. A similar fix was applied upstream forKeyError: 'realname'in v3.8.1.Fix
Subclass
FlickrApias_PatchedFlickrApiand overrideparse_single_photo_infoto fill in missing<usage>attributes with a default of"0"(conservative: cannot print/download/blog/share) before delegating tosuper(). This follows Python best practice of subclassing over direct method replacement.The patch is scoped entirely to
FlickrBotand is trivially removable onceflickr-photos-apiships the upstream fix.