FIX: uuid_compat

This commit is contained in:
Pellaeon Lin
2026-01-31 08:24:50 +00:00
parent 36008fd1fa
commit 1ca54525f2
2 changed files with 27 additions and 2 deletions

View File

@@ -15,6 +15,10 @@ import os
import sys
from pathlib import Path
# Import uuid_compat early to monkey-patch uuid.uuid7 before Django loads migrations
# This fixes migrations generated on Python 3.14+ that reference uuid.uuid7 directly
from archivebox import uuid_compat # noqa: F401
# Force unbuffered output for real-time logs
if hasattr(sys.stdout, 'reconfigure'):
sys.stdout.reconfigure(line_buffering=True)

View File

@@ -1,19 +1,40 @@
"""UUID7 compatibility layer for Python 3.13+
Python 3.14+ has native uuid7 support. For Python 3.13, we use uuid_extensions.
IMPORTANT: We also monkey-patch uuid.uuid7 for backward compatibility with
migrations that were auto-generated on Python 3.14+ systems.
"""
import sys
import uuid
import functools
if sys.version_info >= (3, 14):
from uuid import uuid7
from uuid import uuid7 as _uuid7
else:
try:
from uuid_extensions import uuid7
from uuid_extensions import uuid7 as _uuid7
except ImportError:
raise ImportError(
"uuid_extensions package is required for Python <3.14. "
"Install it with: pip install uuid_extensions"
)
# Monkey-patch uuid module for migrations generated on Python 3.14+
# that reference uuid.uuid7 directly
if not hasattr(uuid, 'uuid7'):
uuid.uuid7 = _uuid7
@functools.wraps(_uuid7)
def uuid7():
"""Generate a UUID7 (time-ordered UUID).
This wrapper ensures Django migrations always reference
'archivebox.uuid_compat.uuid7' regardless of Python version.
"""
return _uuid7()
__all__ = ['uuid7']