Skip to content

fix: upstream bugfixes and proxy support backport#11

Open
vidiecan wants to merge 2 commits intodtqfrom
fix/upstream-bugfixes-and-proxy-support
Open

fix: upstream bugfixes and proxy support backport#11
vidiecan wants to merge 2 commits intodtqfrom
fix/upstream-bugfixes-and-proxy-support

Conversation

@vidiecan
Copy link

Summary

Backport critical bugfixes and improvements from the-library-code/dspace-rest-python upstream (v0.1.14-v0.1.16) into our fork.

Bug Fixes

Critical

  1. User class trailing comma bug (models.py) - Class-level field definitions like name = None, had trailing commas, silently creating tuples (None,) instead of None. This caused incorrect behavior in JSON serialization, comparisons (user.name is None -> False), and any downstream code assuming these are plain values. All 6 affected fields fixed.

  2. get_items() never returning results (client.py) - Was checking collections in r_json['_embedded'] instead of items, meaning this method always returned an empty list even when the API responded correctly.

  3. InProgressSubmission.init double assignment bugs (models.py) - Two bugs: self.step was assigned api_resource['lastModified'] instead of api_resource['step']; when type was present, it overwrote self.lastModified with itself instead of setting self.type.

  4. EntityType.init label overwrite (models.py) - The type field was being assigned to self.label, destroying the correctly parsed label value. Fixed to assign to self.type.

Improvements

  1. Proxy support for all HTTP methods (client.py) - Added PROXY_DICT class variable (reads PROXY_URL env var), proxies parameter to DSpaceClient.__init__(), and proxies=self.proxies to all 7 HTTP methods: authenticate, api_get, api_post, api_post_uri, api_put, api_delete, api_patch.

  2. params parameter added to api_patch() (client.py) - Upstream added params=None to api_patch() and passes it to session.patch(). Previously query parameters could not be passed during PATCH operations.

  3. embedded attribute on HALResource (models.py) - All HAL resources now store _embedded data from API responses into self.embedded. Enables access to embedded sub-resources (e.g. community.embedded['logo']).

API / Breaking Changes

Change Impact Migration
DSpaceClient.__init__() has new proxies parameter Non-breaking - defaults to PROXY_DICT (empty dict if no env var) No action needed; pass proxies={...} to use
api_patch() has new params parameter Non-breaking - defaults to None (same behavior as before) No action needed
HALResource and subclasses now have .embedded attribute Non-breaking - new attribute, defaults to {} Can now access dso.embedded['logo'] etc.
User class fields changed from tuples to proper types Potentially breaking if code depended on buggy tuple values Update user.name == (None,) to user.name is None
get_items() now actually returns items Behavior change - previously always returned [] Code that worked around the bug may need updating
InProgressSubmission.step now correctly populated Behavior change - was previously set to lastModified .step now gets the real value
InProgressSubmission.type now correctly populated Behavior change - was previously always None .type now gets the real value
EntityType.type no longer overwrites .label Behavior change .label now correct, .type now populated

Not Included

The following upstream additions were intentionally not included (new features, not bugfixes):

  • paginated decorator and *_iter auto-paginating methods
  • parse_params / embeds parameter throughout methods
  • create_item_version, create_resource_policy, resolve_identifier_to_dso methods
  • BitstreamFormat, SearchResult model classes
  • smart_open S3 support in create_bitstream
  • Migration from setup.py to pyproject.toml
  • search_objects configuration parameter

Copilot AI review requested due to automatic review settings February 13, 2026 21:50
Copy link

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 backports critical bugfixes and proxy support from the upstream dspace-rest-python library (v0.1.14-v0.1.16). It addresses several serious bugs including tuple-instead-of-None issues in the User class, a broken get_items() method that always returned empty results, and incorrect field assignments in InProgressSubmission and EntityType initialization. The PR also adds HTTP/HTTPS proxy support via environment variable configuration.

Changes:

  • Fixed 6 trailing comma bugs in User class that created tuples instead of None values
  • Fixed get_items() checking wrong key ('collections' → 'items') in API response
  • Fixed InProgressSubmission and EntityType init methods incorrectly assigning fields
  • Added proxy support with PROXY_DICT class variable and proxies parameter to all HTTP methods
  • Added params parameter to api_patch() for query string support
  • Added embedded attribute to HALResource for accessing embedded API sub-resources

Reviewed changes

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

File Description
dspace_rest_client/models.py Fixes User class trailing commas (lines 428-433), InProgressSubmission field assignment bugs (lines 480, 484), EntityType label overwrite bug (line 515), and adds embedded attribute to HALResource (lines 24, 33, 42-43)
dspace_rest_client/client.py Adds PROXY_DICT class variable and proxies parameter (lines 77, 87, 100), adds proxies argument to all 7 HTTP methods (authenticate, api_get, api_post, api_post_uri, api_put, api_delete, api_patch), adds params parameter to api_patch (line 353), and fixes get_items() key check (line 935)

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

return r

def api_patch(self, url, operation, path, value, retry=False):
def api_patch(self, url, operation, path, value, params=None, retry=False):
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

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

Adding the params parameter to api_patch introduces a bug in the retry logic. The existing retry call on line 405 uses: return self.api_patch(url, operation, path, value, True). With the new signature, True is now interpreted as params=True instead of retry=True. The retry call needs to be updated to: return self.api_patch(url, operation, path, value, params=params, retry=True)

Copilot uses AI. Check for mistakes.
@vidiecan vidiecan force-pushed the fix/upstream-bugfixes-and-proxy-support branch from 879e73a to a62f674 Compare February 13, 2026 22:29
Backports critical bugfixes and proxy support from upstream the-library-code/dspace-rest-python.

Bugfixes:
- Fix User model trailing commas that turned fields into tuples
- Fix get_items() using wrong embedded key ('collections' -> 'items')
- Fix InProgressSubmission step assigned from lastModified instead of step
- Fix InProgressSubmission type assigned from lastModified instead of type
- Fix EntityType type field overwriting label
- Fix parse_json to handle None response safely

Improvements:
- Add proxy support via PROXY_URL env var and proxies constructor param
- Add proxies to all HTTP methods (GET, POST, PUT, DELETE, PATCH, send)
- Add proxies to authenticate status check GET
- Add params parameter to api_patch method
- Add embedded attribute to HALResource base class
- Add ITER_PAGE_SIZE class variable (preparation for pagination)
- Add upstream_ref/ to .gitignore
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