Skip to content

fix: update photo asset id property to use correct record#216

Merged
timlaing merged 1 commit intomainfrom
bugfix/add-photos
Apr 3, 2026
Merged

fix: update photo asset id property to use correct record#216
timlaing merged 1 commit intomainfrom
bugfix/add-photos

Conversation

@timlaing
Copy link
Copy Markdown
Owner

@timlaing timlaing commented Apr 3, 2026

Proposed change

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New service (thank you!)
  • New feature (which adds functionality to an existing service)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests
  • Documentation or code sample

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

  • Documentation added/updated to README

@timlaing timlaing self-assigned this Apr 3, 2026
@github-actions github-actions bot added the bugfix label Apr 3, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 3, 2026

📝 Walkthrough

Walkthrough

The PhotoAsset.id property has been updated to return the asset record's identifier instead of the master record's identifier. Corresponding test fixtures have been modified to include explicit asset record names and updated assertions validating that photo asset identifiers are correctly derived from asset records rather than master records.

Changes

Cohort / File(s) Summary
Photo Asset Identifier
pyicloud/services/photos.py
Changed PhotoAsset.id property to return self._asset_record["recordName"] instead of self._master_record["recordName"].
Photo Asset Tests
tests/services/test_photos.py
Updated mock API fixtures with distinct recordName values for CPLAsset records and separate master IDs for CPLMaster records; added assertions validating that PhotoAsset.id matches the asset record identifier.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰✨ A rabbit hops through photo records deep,
Where assets now their own true names do keep,
No master's shadow masks the asset's call—
Each photo finds its own identity true and tall! 📸

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: updating the PhotoAsset.id property to use a different record field.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description check ✅ Passed The PR description is a template with minimal details, but it indicates a bugfix for issue #207 related to the photo asset ID property, which aligns with the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bugfix/add-photos

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@timlaing timlaing marked this pull request as ready for review April 3, 2026 18:40
Copilot AI review requested due to automatic review settings April 3, 2026 18:40
@timlaing timlaing merged commit 386070c into main Apr 3, 2026
23 checks passed
@timlaing timlaing deleted the bugfix/add-photos branch April 3, 2026 18:44
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes photo album operations (notably PhotoAlbum.add_photo) by aligning PhotoAsset.id with the correct iCloud Photos identifier (the asset record’s recordName) rather than the master record’s recordName, addressing issue #207 where adding a photo to an album created an unusable/invisible entry.

Changes:

  • Update PhotoAsset.id to return the asset record recordName.
  • Update photos service tests to include CPLAsset.recordName in mocked responses and assert PhotoAsset.id matches the asset id.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
pyicloud/services/photos.py Switch PhotoAsset.id to use the asset record identifier so album relation writes target the correct record.
tests/services/test_photos.py Adjust mocks/assertions so tests reflect asset-vs-master id distinctions and validate the new id behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 1590 to +1593
@property
def id(self) -> str:
"""Gets the photo id."""
return self._master_record["recordName"]
return self._asset_record["recordName"]
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

The id docstring is now ambiguous: this property returns the asset recordName (used by album relation operations), not the master recordName. Please update the docstring (and ideally mention/expose the master record identifier separately) so API consumers can distinguish the two identifiers.

Copilot uses AI. Check for mistakes.
Comment on lines 1590 to +1593
@property
def id(self) -> str:
"""Gets the photo id."""
return self._master_record["recordName"]
return self._asset_record["recordName"]
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

This change is intended to fix PhotoAlbum.add_photo() by switching PhotoAsset.id to the asset recordName, but there is currently no direct unit test asserting the add_photo() request payload uses the asset id in both itemId and recordName. Adding a focused test would prevent regressions and ensure the original issue (#207) stays fixed.

Copilot uses AI. Check for mistakes.
Comment on lines 2452 to 2456
mock_photo = MagicMock(spec=PhotoAsset)
mock_photo.id = "target_photo"

mock_photo_library.service.session.post.return_value.json.return_value = {
"records": [
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

mock_photo is declared but never used in this test, which makes the test harder to follow. Consider removing it (or using it) since the behavior under test is driven entirely by the mocked session.post().json() response.

Copilot uses AI. Check for mistakes.
Comment on lines 2491 to 2495
mock_photo = MagicMock(spec=PhotoAsset)
mock_photo.id = "different_photo"

mock_photo_library.service.session.post.return_value.json.return_value = {
"records": [
Copy link

Copilot AI Apr 3, 2026

Choose a reason for hiding this comment

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

mock_photo is declared but never used in this test, which makes the test harder to follow. Consider removing it (or using it) since the behavior under test is driven entirely by the mocked session.post().json() response.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to add photo to album

2 participants