From 0e0fa0b3b721fdfc961175af81ef4609212f78f1 Mon Sep 17 00:00:00 2001 From: Codex Date: Thu, 10 Sep 2026 16:24:56 -0400 Subject: [PATCH] fix: store OAuth expiration timestamps as bigint --- fastapi_users_db_sqlalchemy/__init__.py | 4 ++-- tests/conftest.py | 4 ++-- tests/test_users.py | 7 ++++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/fastapi_users_db_sqlalchemy/__init__.py b/fastapi_users_db_sqlalchemy/__init__.py index 467a2bf..0f42dbf 100644 --- a/fastapi_users_db_sqlalchemy/__init__.py +++ b/fastapi_users_db_sqlalchemy/__init__.py @@ -5,7 +5,7 @@ from fastapi_users.db.base import BaseUserDatabase from fastapi_users.models import ID, OAP, UP -from sqlalchemy import Boolean, ForeignKey, Integer, String, func, select +from sqlalchemy import BigInteger, Boolean, ForeignKey, String, func, select from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.orm import Mapped, declared_attr, mapped_column from sqlalchemy.sql import Select @@ -70,7 +70,7 @@ class SQLAlchemyBaseOAuthAccountTable(Generic[ID]): String(length=100), index=True, nullable=False ) access_token: Mapped[str] = mapped_column(String(length=1024), nullable=False) - expires_at: Mapped[Optional[int]] = mapped_column(Integer, nullable=True) + expires_at: Mapped[Optional[int]] = mapped_column(BigInteger, nullable=True) refresh_token: Mapped[Optional[str]] = mapped_column( String(length=1024), nullable=True ) diff --git a/tests/conftest.py b/tests/conftest.py index b7661c6..372169f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -30,7 +30,7 @@ def oauth_account1() -> dict[str, Any]: return { "oauth_name": "service1", "access_token": "TOKEN", - "expires_at": 1579000751, + "expires_at": 2_303_769_600, "account_id": "user_oauth1", "account_email": "king.arthur@camelot.bt", } @@ -41,7 +41,7 @@ def oauth_account2() -> dict[str, Any]: return { "oauth_name": "service2", "access_token": "TOKEN", - "expires_at": 1579000751, + "expires_at": 2_303_769_600, "account_id": "user_oauth2", "account_email": "king.arthur@camelot.bt", } diff --git a/tests/test_users.py b/tests/test_users.py index 4a83e39..98a03ec 100644 --- a/tests/test_users.py +++ b/tests/test_users.py @@ -3,7 +3,7 @@ import pytest import pytest_asyncio -from sqlalchemy import String, exc +from sqlalchemy import BigInteger, String, exc from sqlalchemy.ext.asyncio import ( AsyncEngine, async_sessionmaker, @@ -52,6 +52,10 @@ class UserOAuth(SQLAlchemyBaseUserTableUUID, OAuthBase): ) +def test_oauth_expires_at_uses_big_integer() -> None: + assert isinstance(OAuthAccount.__table__.c.expires_at.type, BigInteger) + + @pytest_asyncio.fixture async def sqlalchemy_user_db() -> AsyncGenerator[SQLAlchemyUserDatabase, None]: engine = create_async_engine(DATABASE_URL) @@ -187,6 +191,7 @@ async def test_queries_oauth( user = await sqlalchemy_user_db_oauth.add_oauth_account(user, oauth_account2) assert len(user.oauth_accounts) == 2 assert user.oauth_accounts[1].account_id == oauth_account2["account_id"] + assert user.oauth_accounts[1].expires_at == oauth_account2["expires_at"] assert user.oauth_accounts[0].account_id == oauth_account1["account_id"] # Update