Skip to content

fix(drizzle-seed): generate RFC 4122 compliant UUID v4 variant bits#5448

Open
isaackaara wants to merge 1 commit intodrizzle-team:mainfrom
isaackaara:fix/seed-uuid-variant-bits
Open

fix(drizzle-seed): generate RFC 4122 compliant UUID v4 variant bits#5448
isaackaara wants to merge 1 commit intodrizzle-team:mainfrom
isaackaara:fix/seed-uuid-variant-bits

Conversation

@isaackaara
Copy link

The UUID v4 generator in drizzle-seed was not setting the variant bits correctly. RFC 4122 requires the first nibble of the 4th group (clock_seq_hi) to be restricted to [8, 9, a, b] (binary 10xx), but the generator was producing any hex digit in that position.

Example of previously invalid output:

6aa65a86-1248-4dcf-e3ec-304ba1343ca5
                     ^ should be 8, 9, a, or b

Fix:
The UUID template now uses a separate V placeholder for the variant position, which is randomly selected from [8, 9, a, b] instead of the full hex range. The version nibble (4) was already correctly hardcoded.

This ensures all generated UUIDs pass validation by libraries like uuid's validate() and PostgreSQL's strict uuid type.

Fixes #5402

The UUID v4 generator was not setting the variant bits correctly.
RFC 4122 requires the first nibble of the 4th group (clock_seq_hi)
to be restricted to [8, 9, a, b] (binary 10xx), but the generator
was producing any hex digit in that position.

Example of previously invalid output:
  6aa65a86-1248-4dcf-e3ec-304ba1343ca5
                     ^ should be 8, 9, a, or b

This fixes the template to constrain the variant nibble to the
allowed values while keeping the rest of the UUID generation
unchanged.

Fixes drizzle-team#5402
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.

[BUG]: drizzle-seed generates invalid RFC 4122 UUID v4 (wrong variant bits)

1 participant