Skip to content

Commit e9eef06

Browse files
jmclaude
andcommitted
fix: address Copilot review (handler guard, header copy, docstrings)
- guard the NullHandler registration so reloads/re-imports don't accumulate duplicate handlers - create_bitstream: copy the session headers before adding Content-Encoding so it doesn't leak onto every subsequent request / across threads - move Collection.as_dict's docstring to the first statement (it was a no-op string literal after code); rename the `dict` builtin-shadow in InProgressSubmission.as_dict Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent feeb399 commit e9eef06

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

dspace_rest_client/client.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@
2828

2929
_logger = logging.getLogger("dspace.client")
3030
# A library must not configure the root logger - that is the consuming
31-
# application's job. Attach a NullHandler so records are dropped unless the
32-
# application opts in to logging.
33-
_logger.addHandler(logging.NullHandler())
31+
# application's job. Attach a NullHandler (once) so records are dropped unless
32+
# the application opts in to logging - guarded so reloads/re-imports don't
33+
# accumulate duplicate handlers.
34+
if not any(isinstance(h, logging.NullHandler) for h in _logger.handlers):
35+
_logger.addHandler(logging.NullHandler())
3436

3537

3638
def parse_json(response):
@@ -857,7 +859,9 @@ def create_bitstream(self, bundle=None, name=None, path=None, mime=None, metadat
857859
files = {'file': (name, fh, mime)}
858860
properties = {'name': name, 'metadata': metadata, 'bundleName': bundle.name}
859861
payload = {'properties': json.dumps(properties) + ';application/json'}
860-
h = self.session.headers
862+
# copy the session headers so this request's Content-Encoding does
863+
# not leak onto every subsequent request (and across threads)
864+
h = dict(self.session.headers)
861865
h.update({'Content-Encoding': 'gzip', 'User-Agent': self.USER_AGENT})
862866
req = Request('POST', url, data=payload, headers=h, files=files)
863867
prepared_req = self.session.prepare_request(req)

dspace_rest_client/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,11 @@ def __init__(self, api_resource=None):
316316
self.type = 'collection'
317317

318318
def as_dict(self):
319-
dso_dict = super().as_dict()
320319
"""
321320
Return a dict representation of this Collection, based on super with collection-specific attributes added
322321
@return: dict of Item for API use
323322
"""
323+
dso_dict = super().as_dict()
324324
collection_dict = {}
325325
return {**dso_dict, **collection_dict}
326326

@@ -488,13 +488,13 @@ def __init__(self, api_resource):
488488

489489
def as_dict(self):
490490
parent_dict = super().as_dict()
491-
dict = {
491+
submission_dict = {
492492
'lastModified': self.lastModified,
493493
'step': self.step,
494494
'sections': self.sections,
495495
'type': self.type
496496
}
497-
return {**parent_dict, **dict}
497+
return {**parent_dict, **submission_dict}
498498

499499
class WorkspaceItem(InProgressSubmission):
500500

0 commit comments

Comments
 (0)