diff --git a/synapseclient/client.py b/synapseclient/client.py index 0c0e30a30..4d612c7f6 100644 --- a/synapseclient/client.py +++ b/synapseclient/client.py @@ -1633,10 +1633,10 @@ def delete(self, obj, version=None): delete. """ - entity_id = id_of(obj) - trace.get_current_span().set_attributes({"synapse.id": entity_id}) # Handle all strings as the Entity ID for backward compatibility if isinstance(obj, str): + entity_id = id_of(obj) + trace.get_current_span().set_attributes({"synapse.id": entity_id}) if version: self.restDELETE(uri=f"/entity/{entity_id}/version/{version}") else: diff --git a/synapseclient/core/upload/multipart_upload.py b/synapseclient/core/upload/multipart_upload.py index 778c23d65..717b6c2f6 100644 --- a/synapseclient/core/upload/multipart_upload.py +++ b/synapseclient/core/upload/multipart_upload.py @@ -15,6 +15,7 @@ import mimetypes import os import re +import typing import requests import threading import time @@ -212,8 +213,9 @@ def _refresh_pre_signed_part_urls( return refreshed_url - def _handle_part(self, part_number, otel_context: Context): - context.attach(otel_context) + def _handle_part(self, part_number, otel_context: typing.Union[Context, None]): + if otel_context: + context.attach(otel_context) with tracer.start_as_current_span("UploadAttempt::_handle_part"): with self._lock: if self._aborted: diff --git a/tests/unit/synapseclient/core/upload/unit_test_multipart_upload.py b/tests/unit/synapseclient/core/upload/unit_test_multipart_upload.py index 9ea7ee4af..74fea01ec 100644 --- a/tests/unit/synapseclient/core/upload/unit_test_multipart_upload.py +++ b/tests/unit/synapseclient/core/upload/unit_test_multipart_upload.py @@ -222,7 +222,7 @@ def test_handle_part_aborted(self, syn): upload._aborted = True with pytest.raises(SynapseUploadAbortedException): - upload._handle_part(5) + upload._handle_part(5, None) def test_handle_part__500(self, syn): """Test that we retry if we encounter a 500 from AWS on a PUT to the signed URL""" @@ -323,7 +323,7 @@ def _handle_part_success_test( mock_session.put.side_effect = [aws_call[1] for aws_call in aws_calls] - result = upload._handle_part(1) + result = upload._handle_part(1, None) expected_put_calls = [aws_call[0] for aws_call in aws_calls] assert mock_session.put.call_args_list == expected_put_calls @@ -465,7 +465,7 @@ def test_handle_part__url_expired_twice(self, syn): mock_session.put.return_value = mock_response with pytest.raises(SynapseHTTPError): - upload._handle_part(1) + upload._handle_part(1, None) def test_call_upload(self, syn): """Verify the behavior of an upload call, it should trigger