Skip to content

fix: set uuid._last_timestamp_v7 to reset uuid7 state#597

Open
decardev wants to merge 4 commits intoadamchainz:mainfrom
decardev:fix/uuid7
Open

fix: set uuid._last_timestamp_v7 to reset uuid7 state#597
decardev wants to merge 4 commits intoadamchainz:mainfrom
decardev:fix/uuid7

Conversation

@decardev
Copy link

@decardev decardev commented Jan 18, 2026

I came across this issue when using both freeegun and time_machine.

3.14::uuid7 keeps track of _last_timestamp_v7 to derive next value. To move forward and back in time this value must be re-set to None.

Copy link
Contributor

@pauloxnet pauloxnet left a comment

Choose a reason for hiding this comment

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

Added a small code suggestion

Comment on lines +934 to +935
if not hasattr(uuid, "uuid7"):
pytest.skip("uuid.uuid7 is not available")
Copy link
Author

Choose a reason for hiding this comment

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

Only to make mypy happy. What is prefered here?
@pytest.mark.skipif(...) or internal check?

@decardev
Copy link
Author

I had to move the logic to the Traveller to resolve nesting or fixture usage.

@adamchainz
Copy link
Owner

You didn't provide a bug report. Please say what happens currently. An exception, faulty uuid generation, ...???

I'm not super in favour of adding a special patch in here for uuid7, since it's somewhat niche, and we could surely add similar patches for dozens of third-party libraries with a similar pattern of storing a timestamp. I'm leaning more towards making this a user responsibliity, but maybe something time-machine can assist with by providing something like a signals system for each time the time changes.

On that note, patching _start won't be sufficient: shift and move_to would also need changing.

@decardev
Copy link
Author

You didn't provide a bug report. Please say what happens currently. An exception, faulty uuid generation, ...???

I'm not super in favour of adding a special patch in here for uuid7, since it's somewhat niche, and we could surely add similar patches for dozens of third-party libraries with a similar pattern of storing a timestamp. I'm leaning more towards making this a user responsibliity, but maybe something time-machine can assist with by providing something like a signals system for each time the time changes.

On that note, patching _start won't be sufficient: shift and move_to would also need changing.

Thank you for the feedback, #601.
Regarding the other points.

  • This is targeting the standard uuid7 introduced on py314, not the third-party one. I completely agree that time_machine should not deal with third-party libraries, but given the introduction of UUID7 I think time_machine should cover it.
  • It seems move_to calls _start() so it works and shift is a positive increase so no need to reset current timestamp.

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.

3 participants