Skip to content

Commit 94ce28e

Browse files
committed
chore: ports various util changes
1 parent a8ebc55 commit 94ce28e

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/labs/models/utils.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
),
7474
]
7575

76+
7677
class IdentifierMixin(object):
7778
"""An ID for a given object
7879
@@ -81,7 +82,8 @@ class IdentifierMixin(object):
8182
techniques.
8283
"""
8384
id: Mapped[pk_uuid]
84-
85+
86+
8587
class DateTimeMixin(object):
8688
"""Stores creation and update timestamps
8789
@@ -96,6 +98,7 @@ class DateTimeMixin(object):
9698
updated_at: Mapped[timestamp_req]
9799
deleted_at: Mapped[timestamp]
98100

101+
99102
class CUDByMixin(object):
100103
""" Adds references to created_by and updated_by users
101104
@@ -104,6 +107,7 @@ class CUDByMixin(object):
104107
last_updated_by_user_id: Mapped[fk_user_uuid_req]
105108
deleted_by_user_id: Mapped[fk_user_uuid]
106109

110+
107111
class ModelCRUDMixin:
108112
"""
109113
A CRUD Mixin designed to abstract CRUD operations for all
@@ -134,14 +138,17 @@ async def create(
134138
new_instance = cls(**kwargs)
135139
async_db_session.add(new_instance)
136140
await async_db_session.commit()
137-
await async_db_session.refresh(new_instance) # Ensure we get the id
141+
await async_db_session.refresh(new_instance) # Ensure we get the id
138142

139143
# This will trigger using the _base_get_query to load any
140-
# relationships we need.
141-
updated_instance = await cls.get(
142-
async_db_session,
143-
new_instance.id
144-
)
144+
# relationships we need. The if statement is to ensure that tables
145+
# like join tables do not always have an id field.
146+
updated_instance = new_instance
147+
if hasattr(cls, "id"):
148+
updated_instance = await cls.get(
149+
async_db_session,
150+
new_instance.id
151+
)
145152

146153
return updated_instance
147154

@@ -257,7 +264,6 @@ async def get_all_in_range(
257264
users = users.scalars().all()
258265
return users
259266

260-
261267
@classmethod
262268
async def get_all(
263269
cls,

src/labs/utils/auth.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
import bcrypt
1818
import jwt
1919

20-
from ..settings import settings
20+
from ..settings import settings
21+
2122

2223
def verify_password(
2324
plain_password,
@@ -32,6 +33,7 @@ def verify_password(
3233
str.encode(hashed_password)
3334
)
3435

36+
3537
def hash_password(password) -> str:
3638
""" Use the crypt context to hash the password
3739
@@ -79,5 +81,5 @@ def create_access_token(
7981
settings.jwt.secret_key.get_secret_value(),
8082
algorithm=settings.jwt.algorithm
8183
)
82-
84+
8385
return encoded_jwt

0 commit comments

Comments
 (0)