From 124809e12c6fd53b5e63895f5ea7eb9c4e3dec8b Mon Sep 17 00:00:00 2001 From: Alex Ioannidis Date: Mon, 6 May 2024 18:34:53 +0200 Subject: [PATCH] files-schema: hide `uri` from serialization Co-Authored-By: Yash Lamba --- invenio_records_resources/records/api.py | 2 -- invenio_records_resources/services/files/schema.py | 2 +- invenio_records_resources/services/files/tasks.py | 2 +- tests/services/files/test_file_service.py | 7 +------ 4 files changed, 3 insertions(+), 10 deletions(-) diff --git a/invenio_records_resources/records/api.py b/invenio_records_resources/records/api.py index bfb3397f..e43709c1 100644 --- a/invenio_records_resources/records/api.py +++ b/invenio_records_resources/records/api.py @@ -20,8 +20,6 @@ from invenio_records.systemfields import DictField, SystemField, SystemFieldsMixin from invenio_records.systemfields.model import ModelField -# TODO move to systemfields folder - class Record(RecordBase, SystemFieldsMixin): """Base class for record APIs. diff --git a/invenio_records_resources/services/files/schema.py b/invenio_records_resources/services/files/schema.py index 190fda4d..07d151ea 100644 --- a/invenio_records_resources/services/files/schema.py +++ b/invenio_records_resources/services/files/schema.py @@ -55,7 +55,7 @@ class Meta: key = Str(required=True) storage_class = Str() - uri = Str() + uri = Str(load_only=True) checksum = Str() size = Integer() diff --git a/invenio_records_resources/services/files/tasks.py b/invenio_records_resources/services/files/tasks.py index 8ef42298..01a8999f 100644 --- a/invenio_records_resources/services/files/tasks.py +++ b/invenio_records_resources/services/files/tasks.py @@ -23,7 +23,7 @@ def fetch_file(service_id, record_id, file_key): try: service = current_service_registry.get(service_id) file_record = service.read_file_metadata(system_identity, record_id, file_key) - source_url = file_record.data["uri"] + source_url = file_record._file.file.uri # download file # verify=True for self signed certificates by default with requests.get(source_url, stream=True, allow_redirects=True) as response: diff --git a/tests/services/files/test_file_service.py b/tests/services/files/test_file_service.py index 2de90fd2..7615cccd 100644 --- a/tests/services/files/test_file_service.py +++ b/tests/services/files/test_file_service.py @@ -109,7 +109,6 @@ def test_file_flow(file_service, location, example_file_record, identity_simple, result = file_service.read_file_metadata(identity_simple, recid, "article.txt") assert result.to_dict()["key"] == file_to_initialise[0]["key"] assert result.to_dict()["storage_class"] == "L" - assert "uri" not in result.to_dict() # Retrieve file result = file_service.get_file_content(identity_simple, recid, "article.txt") @@ -293,7 +292,6 @@ def test_content_and_commit_external_file( result = result.to_dict() assert result["key"] == file_to_initialise[0]["key"] assert result["storage_class"] == "F" - assert "uri" in result # Set content as user content = BytesIO(b"test file content") @@ -317,7 +315,7 @@ def test_content_and_commit_external_file( result = result.to_dict() assert result["key"] == file_to_initialise[0]["key"] assert result["storage_class"] == "F" # not commited yet - assert "uri" in result + assert "uri" not in result # Commit as user with pytest.raises(PermissionDeniedError): @@ -369,7 +367,6 @@ def test_delete_not_committed_external_file( result = result.to_dict() assert result["key"] == file_to_initialise[0]["key"] assert result["storage_class"] == "F" - assert "uri" in result # Delete file file_service.delete_file(identity_simple, recid, "article.txt") @@ -440,7 +437,6 @@ def test_read_not_committed_external_file( result = result.to_dict() assert result["key"] == file_to_initialise[0]["key"] assert result["storage_class"] == "F" - assert "uri" in result # List files result = file_service.list_files(identity_simple, recid) @@ -451,7 +447,6 @@ def test_read_not_committed_external_file( result = result.to_dict() assert result["key"] == file_to_initialise[0]["key"] assert result["storage_class"] == "F" # changed after commit - assert "uri" in result # Retrieve file with pytest.raises(PermissionDeniedError):