Skip to content

Conversation

Arya-A-Nair
Copy link
Contributor

Closes #3394

@Arya-A-Nair Arya-A-Nair force-pushed the feature/xmp-create-method branch from 9183c12 to 7129e69 Compare July 30, 2025 10:26
- Fix missing Dict and List imports in typing
- All XMP setter methods are now working correctly
- All tests pass except one unrelated remote file test
- XmpInformation.create() and all setter methods fully functional
- Code follows existing codebase patterns and style
Copy link

codecov bot commented Jul 31, 2025

Codecov Report

❌ Patch coverage is 99.42363% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.04%. Comparing base (bc318d7) to head (8cabff0).

Files with missing lines Patch % Lines
pypdf/xmp.py 99.42% 0 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3410      +/-   ##
==========================================
+ Coverage   96.97%   97.04%   +0.06%     
==========================================
  Files          54       54              
  Lines        9337     9567     +230     
  Branches     1711     1739      +28     
==========================================
+ Hits         9055     9284     +229     
  Misses        168      168              
- Partials      114      115       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Add tests for ownerDocument None error conditions (lines 459-465, 484, 506, 535, 564, 597)
- Add tests for description element creation paths
- Add tests for attribute handling and edge cases
- Improve test coverage from 95% to 97%
- All XMP functionality thoroughly tested with error conditions and edge cases
@stefan6419846
Copy link
Collaborator

Thanks for the PR. Besides the coverage: Could we please have proper properties instead of a read-only property and a setter? This is not really pythonic.

@Arya-A-Nair
Copy link
Contributor Author

@stefan6419846 yeah sure, I understood my mistake. I'll refactor it and ask for review, once done

@Arya-A-Nair Arya-A-Nair marked this pull request as draft July 31, 2025 12:20
@Arya-A-Nair Arya-A-Nair force-pushed the feature/xmp-create-method branch from d66f82b to 1abdf04 Compare July 31, 2025 12:32
@Arya-A-Nair Arya-A-Nair marked this pull request as ready for review July 31, 2025 12:55
@Arya-A-Nair
Copy link
Contributor Author

@stefan6419846 you can take a look at it now

@stefan6419846
Copy link
Collaborator

Sorry for the delays - I did not yet have the time to properly review these larger changes again. I hope that I manage to look into this in the next days.

@Arya-A-Nair
Copy link
Contributor Author

Hey @stefan6419846 can i contribute to some other issue till that time?

@stefan6419846
Copy link
Collaborator

You can of course look into another issue if you start the corresponding changes from the main code again.

del self.cache[namespace][name]
desc = self._get_or_create_description()

existing_elements = list(desc.getElementsByTagNameNS(namespace, name))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need the list conversion and a separate variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didnt quite understand this, Can you clarify on it?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Will there be any issues if we use the following direct code?

for elem in desc.getElementsByTagNameNS(namespace, name):
    desc.removeChild(elem)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, there would be issues with the direct approach. getElementsByTagNameNS() returns a live NodeList that automatically updates when the DOM changes. If we iterate directly over it while calling removeChild(), the NodeList shrinks and re-indexes during iteration, causing elements to be skipped. The list() conversion creates a static snapshot of the elements to remove, avoiding this iteration-while-modifying problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you think we are fine with this. Then I will go ahead and change it

…erify incremental updates of XMP values without overwriting
… NAMESPACE_PREFIX_MAP to _NAMESPACE_PREFIX_MAP and MINIMAL_XMP to _MINIMAL_XMP
…ate documentation to reflect new approach for incrementally updating XMP metadata fields directly using standard data structures
@Arya-A-Nair
Copy link
Contributor Author

Hey @stefan6419846 can you take a look at this PR?

@stefan6419846
Copy link
Collaborator

I am currently on tour and will not be able to do look into larger PRs until September.

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.

Provide a way to create XMP metadata from scratch
2 participants