Skip to content

Commit

Permalink
Merge pull request #643 from DuncanDHall/skip-refresh
Browse files Browse the repository at this point in the history
Add refresh opt-out on Item.modify_metadata()
  • Loading branch information
jjjake authored Apr 22, 2024
2 parents ac05934 + 894b736 commit d8f2cc3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions internetarchive/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ def modify_metadata(
secret_key=secret_key,
debug=debug,
request_kwargs=request_kwargs,
refresh=False
)


Expand Down
2 changes: 1 addition & 1 deletion internetarchive/cli/ia_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def modify_metadata(item: item.Item, metadata: Mapping, args: Mapping) -> Respon
r = item.modify_metadata(metadata, target=args['--target'], append=append,
expect=expect, priority=args['--priority'],
append_list=append_list, headers=args['--header'],
insert=insert, timeout=args['--timeout'])
insert=insert, timeout=args['--timeout'], refresh=False)
assert isinstance(r, Response) # mypy: modify_metadata() -> Request | Response
except ItemLocateError as exc:
print(f'{item.identifier} - error: {exc}', file=sys.stderr)
Expand Down
8 changes: 6 additions & 2 deletions internetarchive/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,8 @@ def modify_metadata(self,
debug: bool = False,
headers: Mapping | None = None,
request_kwargs: Mapping | None = None,
timeout: int | float | None = None) -> Request | Response:
timeout: int | float | None = None,
refresh: bool = True) -> Request | Response:
"""Modify the metadata of an existing item on Archive.org.
Note: The Metadata Write API does not yet comply with the
Expand All @@ -801,6 +802,8 @@ def modify_metadata(self,
:param append_list: Append values to an existing multi-value
metadata field. No duplicate values will be added.
:param refresh: Refresh the item metadata after the request.
:returns: A Request if debug else a Response.
Usage::
Expand Down Expand Up @@ -850,7 +853,8 @@ def modify_metadata(self,
return prepared_request
resp = self.session.send(prepared_request, **request_kwargs)
# Re-initialize the Item object with the updated metadata.
self.refresh()
if refresh:
self.refresh()
return resp

# TODO: `list` parameter name shadows the Python builtin
Expand Down
3 changes: 1 addition & 2 deletions tests/cli/test_ia_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ def test_ia_metadata_modify(capsys):
md_rsp = ('{"success":true,"task_id":447613301,'
'"log":"https://catalogd.archive.org/log/447613301"}')
with IaRequestsMock() as rsps:
rsps.add_metadata_mock('nasa')
rsps.add_metadata_mock('nasa', method=responses.GET)
rsps.add_metadata_mock('nasa', body=md_rsp, method=responses.POST)
rsps.add_metadata_mock('nasa')
valid_key = f'foo-{int(time())}'
ia_call(['ia', 'metadata', '--modify', f'{valid_key}:test_value', 'nasa'])
out, err = capsys.readouterr()
Expand Down

0 comments on commit d8f2cc3

Please sign in to comment.