Skip to content

Conversation

@sinisaos
Copy link
Member

Related to #1264

Comment on lines -64 to +65
with pytest.warns(None) as recorded_warnings:
with warnings.catch_warnings() as recorded_warnings:
warnings.simplefilter("error")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was made because Python 3.14 does not allow the type None in pytest.warns() (TypeError: exceptions must be derived from Warning, not <class 'NoneType'>)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, took me a while, but I get what's going on now.

I was a bit confused by warnings.simplefilter("error"), but that's turning each warning into an exception, so you no longer need to check the length of the warnings.


def test_reflect_all_tables(self):
run_sync(self.table_storage.reflect())
run_sync(self.table_storage.reflect(exclude=["migration"]))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason in Python 3.14 (which I don't understand) the migration table is included in the table storage and the tests fail. I exclude the migration table from table storage to prevent this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, interesting. I'll try it locally. I wonder what changed in Python 3.14 to cause this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for me locally. Maybe your test database has a stale migration table or something?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, OK - I can see it failing now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I just run that test by itself, it's OK. But if I run the entire test suite then it fails.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be to do with the newer version of Pytest.

In conftest.py we have drop_tables which is meant to clean up these tables. I wonder if that's not running. Worth investigating.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked, and drop_tables does get run before the tests run. So the problem is some previous test is creating the migration table but not cleaning it up.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I just run that test by itself, it's OK. But if I run the entire test suite then it fails.

That's exactly what's happening.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this is a good idea, but we can force the migration table drop in the test setup just to make sure that migration table is dropped. This works in Py3.14 and Py3.12. Something like this

from piccolo.apps.migrations.commands.base import Migration

@engines_only("postgres", "cockroach")
class TestTableStorage(TestCase):
    def setUp(self) -> None:
        Migration.raw("DROP TABLE IF EXISTS migration").run_sync() # here
        self.table_storage = TableStorage()
        for table_class in (Manager, Band):
            table_class.create_table().run_sync()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sinisaos Yes, that works.

I managed to figure out which tests were leaving the migration table in the database. I added this auto fixture to conftest.py:

@pytest.fixture(autouse=True)
def migration_table_detector():
    yield
    response = asyncio.run(
        ENGINE._run_in_new_connection(
            "SELECT * FROM information_schema.tables WHERE table_name = 'migration'"
        )
    )
    if len(response) > 0:
        breakpoint()

There were two tests which ran migration commands, and the migration table was being created.

Maybe in the future we can run each test in a transaction to avoid these kinds of problems, but not a priority right now.

I've been able to fix the relevant tests.

@dantownsend
Copy link
Member

I've made a fresh virtual env using Python 3.14, but can't install some of our pip dependencies. Will try again tomorrow.

@sinisaos
Copy link
Member Author

@dantownsend Strange. Now I'm cloned the branch in fresh virtualenv and everything works in my case. Which OS do you use? I use Linux Mint 22.2 Cinnamon which is based on Ubuntu 24.04 LTS.

@dantownsend
Copy link
Member

Looks good, thanks! 👍

@dantownsend dantownsend merged commit 5046256 into piccolo-orm:master Oct 21, 2025
46 checks passed
@dantownsend dantownsend mentioned this pull request Oct 21, 2025
@sinisaos sinisaos deleted the py3.14_support branch October 22, 2025 04:10
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

Successfully merging this pull request may close these issues.

2 participants