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
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
Expand All @@ -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",
}
7 changes: 6 additions & 1 deletion tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down