Skip to content

Commit

Permalink
fix: no user id
Browse files Browse the repository at this point in the history
  • Loading branch information
egor-romanov committed Nov 16, 2023
1 parent a9297e2 commit 312e52d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/vecs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 3 additions & 2 deletions src/vecs/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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():
Expand Down Expand Up @@ -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(
Expand Down
11 changes: 8 additions & 3 deletions src/vecs/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 312e52d

Please sign in to comment.