Urgent.News

What's breaking now, across thousands of outlets.

Tech

My Migration Generator Shuffled Itself for Two Days. PYTHONHASHSEED Was the Coin Flip.

Two consecutive runs of the same command emitted the same SQL statements in a different order, and I did not believe my own terminal. I re-ran it four times, redirected each run into a file, and compared them the way you check whether the fridge light really goes off. The statement set was identical, the sequence was not, and the applied-version check that consumed it failed on roughly every…

The article describes a bug in Python's dependency resolver, which shuffled the order of SQL statements emitted by the command `python -m myapp.migrate --print`. The author discovered this issue after running the command multiple times and noticing that the ordering of the statements changed between runs, but not within a single run.

They tested various hypotheses, such as parallel test harnesses, filesystem glob order, SQLAlchemy metadata ordering, stale caches, and unset locale or collation differences. None of these turned out to be the cause. The root cause was eventually found to be the salted hash table layout used by Python for set iteration order, which depends on the process-specific `PYTHONHASHSEED`.

The author created a reproducible script (`repro_seed.py`) to demonstrate the issue, and tested the problem on different seeds. They also provided a `seed-matrix.sh` script to check if the generated output is seed-dependent or seed-stable across multiple seeds.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

What are your goals for the week? #196

What are your goals for the week? What are you building this week? What do you want to learn? What events are you attending this week? This Week's Goals. Job Search. Network Apply Project work.

More from Monday 14 September →