Fix: Python as trying to compare a timezone aware date object with a timezone naive (in the database) object and giving errors.
This commit is contained in:
parent
e823a35611
commit
bf4d51cc30
@ -35,7 +35,11 @@ class TokenData(BaseModel):
|
||||
|
||||
def create_access_token(*, data: dict[str, Any], expires_delta: timedelta | None = None) -> str:
|
||||
to_encode = data.copy()
|
||||
expire = datetime.now(UTC) + expires_delta if expires_delta else datetime.now(UTC) + timedelta(minutes=15)
|
||||
expire = (
|
||||
datetime.now(UTC).replace(tzinfo=None) + expires_delta
|
||||
if expires_delta
|
||||
else datetime.now(UTC).replace(tzinfo=None) + timedelta(minutes=15)
|
||||
)
|
||||
to_encode.update({"exp": expire})
|
||||
encoded_jwt = jwt.encode(to_encode, settings.SECRET_KEY, algorithm=settings.ALGORITHM)
|
||||
return encoded_jwt
|
||||
|
@ -67,7 +67,7 @@ class Attendance:
|
||||
self.attendance_type = attendance_type
|
||||
self.user_id = user_id
|
||||
self.amount = amount
|
||||
self.creation_date = creation_date or datetime.now(UTC)
|
||||
self.creation_date = creation_date or datetime.now(UTC).replace(tzinfo=None)
|
||||
self.is_valid = is_valid
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
|
@ -41,7 +41,7 @@ class Client:
|
||||
self.name = name
|
||||
self.enabled = enabled
|
||||
self.otp = otp
|
||||
self.creation_date = datetime.now(UTC) if creation_date is None else creation_date
|
||||
self.creation_date = datetime.now(UTC).replace(tzinfo=None) if creation_date is None else creation_date
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
|
||||
|
@ -32,6 +32,6 @@ class DbImage:
|
||||
self.resource_type = resource_type
|
||||
self.image = image
|
||||
self.thumbnail = thumbnail
|
||||
self.creation_date = creation_date or datetime.now(UTC)
|
||||
self.creation_date = creation_date or datetime.now(UTC).replace(tzinfo=None)
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
|
@ -40,6 +40,6 @@ class LoginHistory:
|
||||
) -> None:
|
||||
self.user_id = user_id
|
||||
self.client_id = client_id
|
||||
self.date = datetime.now(UTC) if date is None else date
|
||||
self.date = datetime.now(UTC).replace(tzinfo=None) if date is None else date
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
|
@ -52,7 +52,7 @@ class RateContract:
|
||||
self.valid_till = valid_till
|
||||
self.narration = narration
|
||||
self.user_id = user_id
|
||||
self.creation_date = creation_date or datetime.now(UTC)
|
||||
self.last_edit_date = last_edit_date or datetime.now(UTC)
|
||||
self.creation_date = creation_date or datetime.now(UTC).replace(tzinfo=None)
|
||||
self.last_edit_date = last_edit_date or datetime.now(UTC).replace(tzinfo=None)
|
||||
if id_ is not None:
|
||||
self.id = id_
|
||||
|
@ -72,8 +72,8 @@ class Voucher:
|
||||
self.is_starred = is_starred if is_starred is not None else False
|
||||
self.narration = narration
|
||||
self.posted = posted
|
||||
self.creation_date = creation_date or datetime.now(UTC)
|
||||
self.last_edit_date = last_edit_date or datetime.now(UTC)
|
||||
self.creation_date = creation_date or datetime.now(UTC).replace(tzinfo=None)
|
||||
self.last_edit_date = last_edit_date or datetime.now(UTC).replace(tzinfo=None)
|
||||
self.voucher_type = voucher_type
|
||||
self.user_id = user_id
|
||||
if poster_id is not None:
|
||||
|
@ -203,7 +203,7 @@ def update_voucher(id_: uuid.UUID, data: schema_in.EmployeeBenefitIn, user: User
|
||||
voucher.narration = data.narration
|
||||
voucher.user_id = user.id_
|
||||
voucher.posted = False
|
||||
voucher.last_edit_date = datetime.now(UTC)
|
||||
voucher.last_edit_date = datetime.now(UTC).replace(tzinfo=None)
|
||||
return voucher
|
||||
|
||||
|
||||
|
@ -163,7 +163,7 @@ def update_voucher(id_: uuid.UUID, data: schema_in.IncentiveIn, user: UserToken,
|
||||
voucher.narration = data.narration
|
||||
voucher.user_id = user.id_
|
||||
voucher.posted = False
|
||||
voucher.last_edit_date = datetime.now(UTC)
|
||||
voucher.last_edit_date = datetime.now(UTC).replace(tzinfo=None)
|
||||
return voucher
|
||||
|
||||
|
||||
|
@ -234,7 +234,7 @@ def update_voucher(
|
||||
voucher.narration = data.narration
|
||||
voucher.user_id = user.id_
|
||||
voucher.posted = False
|
||||
voucher.last_edit_date = datetime.now(UTC)
|
||||
voucher.last_edit_date = datetime.now(UTC).replace(tzinfo=None)
|
||||
|
||||
for item in voucher.journals:
|
||||
if item.debit == 1:
|
||||
|
@ -143,7 +143,7 @@ def update_voucher(id_: uuid.UUID, data: schema_in.JournalIn, user: UserToken, d
|
||||
voucher.narration = data.narration
|
||||
voucher.user_id = user.id_
|
||||
voucher.posted = False
|
||||
voucher.last_edit_date = datetime.now(UTC)
|
||||
voucher.last_edit_date = datetime.now(UTC).replace(tzinfo=None)
|
||||
|
||||
for i in range(len(voucher.journals), 0, -1):
|
||||
item = voucher.journals[i - 1]
|
||||
|
@ -57,10 +57,10 @@ async def login_for_access_token(
|
||||
delete(LoginHistory)
|
||||
.where(
|
||||
or_(
|
||||
LoginHistory.date < datetime.now(UTC) - timedelta(days=30),
|
||||
LoginHistory.date < datetime.now(UTC).replace(tzinfo=None) - timedelta(days=30),
|
||||
LoginHistory.client_id.in_(
|
||||
select(Client.id).where(
|
||||
Client.creation_date < datetime.now(UTC) - timedelta(days=3),
|
||||
Client.creation_date < datetime.now(UTC).replace(tzinfo=None) - timedelta(days=3),
|
||||
Client.enabled == False, # noqa: E712
|
||||
)
|
||||
),
|
||||
@ -70,7 +70,7 @@ async def login_for_access_token(
|
||||
)
|
||||
db.execute(
|
||||
delete(Client).where(
|
||||
Client.creation_date < datetime.now(UTC) - timedelta(days=3),
|
||||
Client.creation_date < datetime.now(UTC).replace(tzinfo=None) - timedelta(days=3),
|
||||
Client.enabled == False, # noqa: E712
|
||||
)
|
||||
)
|
||||
|
@ -231,7 +231,7 @@ def update_voucher(id_: uuid.UUID, data: schema_in.PurchaseIn, user: UserToken,
|
||||
voucher.narration = data.narration
|
||||
voucher.user_id = user.id_
|
||||
voucher.posted = False
|
||||
voucher.last_edit_date = datetime.now(UTC)
|
||||
voucher.last_edit_date = datetime.now(UTC).replace(tzinfo=None)
|
||||
return voucher
|
||||
|
||||
|
||||
|
@ -224,7 +224,7 @@ def update_voucher(id_: uuid.UUID, data: schema_in.PurchaseIn, user: UserToken,
|
||||
voucher.narration = data.narration
|
||||
voucher.user_id = user.id_
|
||||
voucher.posted = False
|
||||
voucher.last_edit_date = datetime.now(UTC)
|
||||
voucher.last_edit_date = datetime.now(UTC).replace(tzinfo=None)
|
||||
return voucher
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user