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

fix: coerce pydantic AnyUri to str when needed #377

Merged
merged 1 commit into from
Nov 13, 2023

Conversation

dwinston
Copy link
Collaborator

fixes #376

@@ -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(
Copy link
Collaborator

@eecavanna eecavanna Nov 13, 2023

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).

class AccessURL(BaseModel):
headers: Optional[Dict[str, str]] = None
url: AnyUrl
@field_serializer("url")
def serialize_url(self, url: AnyUrl, _info):
return str(url)

Copy link
Collaborator Author

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.

@eecavanna
Copy link
Collaborator

LGTM! I posted a comment that I do not consider a blocker for merge.

@eecavanna eecavanna self-requested a review November 13, 2023 18:30
)
else:
access = AccessURL(url=method.access_url.url)
return requests.get(access.url)
return requests.get(str(access.url))
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

@dwinston dwinston merged commit 1eacc43 into main Nov 13, 2023
@dwinston dwinston deleted the 376-pydantic-url-coerce branch November 13, 2023 18:37
@eecavanna
Copy link
Collaborator

Thanks @dwinston !

FYI @brynnz22 , here's the web page I look at to see whether code that was "just now" merged into main has been deployed to the production environment yet:

https://github.com/microbiomedata/nmdc-runtime/actions

image

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pydantic AttributeError (on Dagit) after using /metadata/json:submit endpoint
2 participants