-
Notifications
You must be signed in to change notification settings - Fork 5
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
fix: coerce pydantic AnyUri to str when needed #377
Conversation
@@ -194,15 +194,17 @@ def get_object_bytes(self, object_id) -> requests.Response: | |||
access = AccessURL( | |||
**self.get_object_access(object_id, method.access_id).json() | |||
) | |||
if access.url.startswith( | |||
if str(access.url).startswith( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note: Maybe there's already a way to get the url
property of access
as a string, rather than casting it here. I noticed the AccessURL
class has this method defined (I don't know what the decorator does yet).
nmdc-runtime/nmdc_runtime/api/models/object.py
Lines 31 to 37 in 7bc8f40
class AccessURL(BaseModel): | |
headers: Optional[Dict[str, str]] = None | |
url: AnyUrl | |
@field_serializer("url") | |
def serialize_url(self, url: AnyUrl, _info): | |
return str(url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the field_serializer
decorator ensures that when .model_dump()
is called on a model, url
is stringified, but this doesn't hold for direct attribute access, i.e. <model>.url
.
LGTM! I posted a comment that I do not consider a blocker for merge. |
) | ||
else: | ||
access = AccessURL(url=method.access_url.url) | ||
return requests.get(access.url) | ||
return requests.get(str(access.url)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side note: Instead of casting it 3x, we could store the casted result as access_url_str
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I considered that. we get some url (format) validation by keeping to the model until the return.
Thanks @dwinston ! FYI @brynnz22 , here's the web page I look at to see whether code that was "just now" merged into https://github.com/microbiomedata/nmdc-runtime/actions ![]() Once both of those workflow runs has a green checkmark next to it, the code has been deployed to both the development and production environments. |
fixes #376