Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlmodel compat #149

Open
falkben opened this issue Dec 28, 2023 · 1 comment
Open

sqlmodel compat #149

falkben opened this issue Dec 28, 2023 · 1 comment

Comments

@falkben
Copy link
Owner

falkben commented Dec 28, 2023

newer versions of sqlmodel fail the test suite. occurred when going from sqlmodel 0.0.11 to 0.0.12, which is when sqlalchemy 2.0 support was added

@falkben
Copy link
Owner Author

falkben commented Dec 28, 2023

output from failing tests

session = <sqlmodel.orm.session.Session object at 0x7f0b3e1eda50>

    def test_ingest_item_twice(session: Session):
        appid = "620"
        app_data = get_apps_data([appid])[0]
    
        app = handler.import_single_app(session, app_data)
        apps_achievements_data = get_apps_achievements([app])
        handler.store_apps_achievements(session, apps_achievements_data)
    
        # now ingest the data again
        app_double = handler.import_single_app(session, app_data)
        apps_achievements_data = get_apps_achievements([app])
        handler.store_apps_achievements(session, apps_achievements_data)
    
        # assert that the two instances are the same
        assert app == app_double
    
        #  app is only in db once
        apps = session.exec(
            select(models.SteamApp).filter(models.SteamApp.appid == app.appid)
        ).all()
        assert len(apps) == 1
    
        # genres
        genres = session.exec(
            select(models.Genre).filter(models.Genre.steam_apps.any(appid=appid))
        ).all()
        assert len(genres) == len(app.genres)
    
        achievements = session.exec(
            select(models.Achievement).filter(models.Achievement.steam_app == app)
        ).all()
>       assert len(achievements) == app.achievements_total
E       AssertionError: assert 0 == 51
E        +  where 0 = len([])
E        +  and   51 = SteamApp(updated=datetime.datetime(2023, 12, 28, 20, 0, 42, 881386), appid=620, initial_price=999, recommendations=215...core=95, is_free=False, created=datetime.datetime(2023, 12, 28, 20, 0, 42, 802579), achievements_total=51, type='game').achievements_total

tests/test_handler.py:113: AssertionError
____________________ test_updates_on_diff_achievement_data _____________________

session = <sqlmodel.orm.session.Session object at 0x7f0b3dd5e010>
portal_app = SteamApp(updated=datetime.datetime(2023, 12, 28, 20, 0, 43, 68428), appid=620, initial_price=999, recommendations=2159...score=95, is_free=False, created=datetime.datetime(2023, 12, 28, 20, 0, 43, 69890), achievements_total=51, type='game')
portal_achievements = None

    def test_updates_on_diff_achievement_data(
        session: Session, portal_app: models.SteamApp, portal_achievements
    ):
        """assert updates on diff achievement data"""
        apps_achievements_data = get_apps_achievements([portal_app])
        portal_achievements_data = apps_achievements_data[0]
        modified_achievement_name = portal_achievements_data[1][0]["name"]
        portal_achievements_data[1][0]["percent"] = 100
        handler.store_apps_achievements(session, [portal_achievements_data])
    
        modified_achievement = next(
            (
                achievement
                for achievement in portal_app.achievements
                if achievement.name == modified_achievement_name
            ),
            None,
        )
>       assert modified_achievement
E       assert None

tests/test_handler.py:149: AssertionError
______________________ test_duplicate_achievements_on_app ______________________

session = <sqlmodel.orm.session.Session object at 0x7f0b3e17fa90>
portal_app = SteamApp(updated=datetime.datetime(2023, 12, 28, 20, 0, 43, 231675), appid=620, initial_price=999, recommendations=215...core=95, is_free=False, created=datetime.datetime(2023, 12, 28, 20, 0, 43, 233092), achievements_total=51, type='game')
portal_achievements = None

    def test_duplicate_achievements_on_app(
        session: Session, portal_app: models.SteamApp, portal_achievements
    ):
        """App with duplicated achievements
        assert clear out achievements with updates
        """
    
        # duplicate the first achievement
>       first_achievement = portal_app.achievements[0]
E       IndexError: list index out of range

tests/test_handler.py:161: IndexError
=============================== warnings summary ===============================
tests/test_handler.py: 264 warnings
tests/test_main.py: 32 warnings
  /home/runner/work/steam-to-sqlite/steam-to-sqlite/steam2sqlite/handler.py:22: DeprecationWarning: 
          🚨 You probably want to use `session.exec()` instead of `session.query()`.
  
          `session.exec()` is SQLModel's own short version with increased type
          annotations.
  
          Or otherwise you might want to use `session.execute()` instead of
          `session.query()`.
          
    instance = session.query(model).filter_by(**kwargs).first()

tests/test_handler.py::test_ingest_item_twice
tests/test_handler.py::test_updates_on_diff_achievement_data
tests/test_handler.py::test_duplicate_achievements_on_app
tests/test_main.py::test_main
  /opt/hostedtoolcache/Python/3.11.7/x64/lib/python3.11/site-packages/sqlmodel/orm/session.py:68: SAWarning: Object of type <Achievement> not in session, add operation along 'SteamApp.achievements' will not proceed (This warning originated from the Session 'autoflush' process, which was invoked automatically in response to a user-initiated operation.)
    results = super().execute(

tests/test_handler.py::test_ingest_item_twice
tests/test_handler.py::test_updates_on_diff_achievement_data
tests/test_handler.py::test_duplicate_achievements_on_app
tests/test_main.py::test_main
  /home/runner/work/steam-to-sqlite/steam-to-sqlite/steam2sqlite/handler.py:62: SAWarning: Object of type <Achievement> not in session, add operation along 'SteamApp.achievements' will not proceed
    session.commit()

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

---------- coverage: platform linux, python 3.11.7-final-0 -----------
Coverage XML written to file coverage.xml

=========================== short test summary info ============================
FAILED tests/test_handler.py::test_ingest_item_twice - AssertionError: assert 0 == 51
 +  where 0 = len([])
 +  and   51 = SteamApp(updated=datetime.datetime(2023, 12, 28, 20, 0, 42, 881386), appid=620, initial_price=999, recommendations=215...core=95, is_free=False, created=datetime.datetime(2023, 12, 28, 20, 0, 42, 802579), achievements_total=51, type='game').achievements_total
FAILED tests/test_handler.py::test_updates_on_diff_achievement_data - assert None
FAILED tests/test_handler.py::test_duplicate_achievements_on_app - IndexError: list index out of range
================== 3 failed, 9 passed, 304 warnings in 9.31s ===================

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant