Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions fastapi_users_db_sqlalchemy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down
21 changes: 21 additions & 0 deletions tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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