-
Notifications
You must be signed in to change notification settings - Fork 126
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
Update WeaviateDocumentStore authentication to use new Secret class #425
Conversation
""" | ||
|
||
access_token: Secret = field(default_factory=lambda: Secret.from_env_var(["WEAVIATE_ACCESS_TOKEN"])) | ||
expires_in: Secret = field(default_factory=lambda: Secret.from_env_var(["WEAVIATE_EXPIRES_IN"], strict=False)) |
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.
This doesn't look like a secret. Let's just make it a regular int that defaults to 60.
""" | ||
|
||
|
||
@dataclass |
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.
Let's freeze all dataclasses.
if "type" not in data: | ||
msg = "Missing 'type' in serialization data" | ||
raise DeserializationError(msg) | ||
return _AUTH_CLASSES[data["type"]]._from_dict(data) |
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.
Let's just move the map into the function.
integrations/weaviate/src/haystack_integrations/document_stores/weaviate/document_store.py
Show resolved
Hide resolved
""" | ||
Converts the object to a dictionary representation for serialization. | ||
""" | ||
# We assume all fields are Secret instances |
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.
We should check instead of assuming, especially if the expires_in
field is going to be an int
(see below.)
return default_to_dict( | ||
self, | ||
**_fields, | ||
) |
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.
I'd be more comfortable if we used an explicit enum instead of the full type name. That way, it won't break if we move/rename the underlying classes.
Fixes #369.
Weaviate supports different manner of authentication via some utility dataclasses.
Cause of this it wasn't feasible to use an init parameterer for each possible secret, so we mirrored a bit their utility classes structures to use the
Secret
class.You'll notice that I used a
default_factory
in all dataclasses fields cause we can't usedefault
asSecret
is not a frozen dataclass in the latest beta. When that changes we should be able to usedefault
.