From 312e52dd70c9e08dc56ce11d00a3c2e28f99ae5f Mon Sep 17 00:00:00 2001 From: egor-romanov Date: Thu, 16 Nov 2023 17:25:35 +0400 Subject: [PATCH] fix: no user id --- src/vecs/__init__.py | 2 +- src/vecs/client.py | 5 +++-- src/vecs/collection.py | 11 ++++++++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/vecs/__init__.py b/src/vecs/__init__.py index 0aae6d3..e781512 100644 --- a/src/vecs/__init__.py +++ b/src/vecs/__init__.py @@ -24,7 +24,7 @@ def create_client( - connection_string: str, *, skip_auth: bool = True, user_id: str | None = None + connection_string: str, *, skip_auth: bool = True, user_id: str = None ) -> Client: """Creates a client from a Postgres connection string""" return Client(connection_string, skip_auth=skip_auth, user_id=user_id) diff --git a/src/vecs/client.py b/src/vecs/client.py index 497ae4a..32a93dc 100644 --- a/src/vecs/client.py +++ b/src/vecs/client.py @@ -68,6 +68,7 @@ def __init__( self.skip_auth = skip_auth self.meta = MetaData(schema="vecs") self.Session = sessionmaker(self.engine) + self.set_user(user_id) if not self.skip_auth: with self.Session() as sess: @@ -77,8 +78,6 @@ def __init__( "select installed_version from pg_available_extensions where name = 'vector' limit 1;" ) ).scalar_one() - if user_id: - self.set_user(user_id) with self.Session() as sess: with sess.begin(): @@ -260,6 +259,8 @@ def set_user(self, user_id: str) -> None: None """ self._user_id = user_id + if not self._user_id: + return with self.Session() as sess: with sess.begin(): user = sess.execute( diff --git a/src/vecs/collection.py b/src/vecs/collection.py index 1f0762d..6f6669d 100644 --- a/src/vecs/collection.py +++ b/src/vecs/collection.py @@ -155,7 +155,7 @@ class Collection: Note: Some methods of this class can raise exceptions from the `vecs.exc` module if errors occur. """ - _user_id: str | None = None + _user_id: str = None """ PRIVATE @@ -208,8 +208,7 @@ def __init__( "Dimensions reported by adapter, dimension, and collection do not match" ) - if user_id: - self.set_user(user_id) + self.set_user(user_id) def __repr__(self): """ @@ -607,6 +606,12 @@ def set_user(self, user_id: str) -> None: None """ self._user_id = user_id + if not self._user_id: + self.user_email = None + self.user_role = None + self.user_app_metadata = None + return + with self.client.Session() as sess: with sess.begin(): user = sess.execute(