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/test_users.py b/tests/test_users.py index 4a83e39..2607c4d 100644 --- a/tests/test_users.py +++ b/tests/test_users.py @@ -219,3 +219,24 @@ async def test_queries_oauth( "foo", "bar" ) assert unknown_oauth_user is None + + +@pytest.mark.asyncio +async def test_queries_oauth_expires_at_after_2038( + sqlalchemy_user_db_oauth: SQLAlchemyUserDatabase[UserOAuth, UUID_ID], + oauth_account1: dict[str, Any], +): + """It should store an expiry past the 32 bit signed limit.""" + # 2038-01-19T03:14:08Z, one second past the largest signed 32 bit value + expires_at = 2147483648 + + user = await sqlalchemy_user_db_oauth.create( + {"email": "lancelot@camelot.bt", "hashed_password": "guinevere"} + ) + user = await sqlalchemy_user_db_oauth.add_oauth_account( + user, {**oauth_account1, "expires_at": expires_at} + ) + + oauth_user = await sqlalchemy_user_db_oauth.get(user.id) + assert oauth_user is not None + assert oauth_user.oauth_accounts[0].expires_at == expires_at