Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add refresh opt-out on Item.modify_metadata() #643

Merged
merged 2 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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