Repository navigation
Implement UUID proposer, fix compile_timestampltz_ddb and pyproject.toml - #169
Conversation
| ``as_generic``) are recognised directly; a plain ``String`` *primary key* | ||
| column is checked against a sample of its real values instead, matching each | ||
| one against the canonical UUID pattern. Fixed column length alone is too | ||
| weak a signal: an unrelated natural key can coincidentally share a UUID's |
There was a problem hiding this comment.
I would say these last two sentences are not the best thing for a docstring, but more a comment in the code. Doesn't really matter though.
There was a problem hiding this comment.
I have moved the last two sentences next to the code it explains: uuid.py:128-131
| ) -> str: | ||
| """Render TIMESTAMP_LTZ as TIMESTAMP_LTZ.""" | ||
| return compiler.process(element, **kw) | ||
| return compiler.visit_TIMESTAMP_LTZ(element, **kw) |
| # type and reflect a UUID primary key as a plain fixed-length string, so | ||
| # this is the only signal available (from column metadata alone, with no | ||
| # access to the real data) that such a column actually holds UUIDs. | ||
| _UUID_STRING_LENGTHS = frozenset({32, 36}) |
There was a problem hiding this comment.
I don't love that this is repeated from uuid.py, but I see why you might not have wanted to add a dependency. Alternatively, just removing these changes would be OK. Not sure.
There was a problem hiding this comment.
I’ve removed the make.py change and the three related tests in test_make.py. I checked, and propose correctly recommends the UUID proposer for a Snowflake string UUID column without it, so the length-based default wasn’t needed. UUID detection now lives only in the proposer, which samples the real values instead of relying on length.
| from tests.utils import DatafakerTestCase | ||
|
|
||
|
|
||
| class UuidProposerUnitTests(DatafakerTestCase): |
There was a problem hiding this comment.
I think these test don't really test anything. What would we do if one failed?
There was a problem hiding this comment.
I’ve removed those tests because they only restated constants.
nikk-nikaznan
left a comment
There was a problem hiding this comment.
Looks good! I managed to run with snowflakes, and it works
Co-authored-by: nikk-nikaznan <48319650+nikk-nikaznan@users.noreply.github.com>
|
I’ve also included a small fix in Problem: running
Fix: |
Summary
Adds a generator and proposer for UUID primary keys, so columns that hold UUIDs, including databases like Snowflake that have no native UUID column type and store them as plain strings, get sensible synthetic data instead of a generic string/password generator.
Fixes SAFEHR-data/datafaker#149
UUID proposer (
datafaker/proposers/uuid.py, new)UuidProposergenerates fresh, random version-4 UUIDs (generic.cryptographic.uuid), treated as structurally fresh/unique for ranking purposes.UuidProposerFactoryoffers it for native UUID types (SQLAlchemyUuid, PostgreSQLUUID, MS-SQLUNIQUEIDENTIFIER), and forStringprimary keys without a native type (e.g. Snowflake) by sampling real values and checking the UUID pattern — avoiding false positives from a coincidentally UUID-length natural key, and catching unconstrained-length columns a length-only check would miss. Falls back to a length heuristic only when there’s no data to sample.everything_factory.Default generator fallback (
datafaker/make.py)_string_generatornow also treats a 32/36-charStringPK as a UUID when building the no-data config skeleton.Snowflake
TIMESTAMP_LTZfix (datafaker/dialects.py)compiler.process()on its own element, re-entering itself. Now callscompiler.visit_TIMESTAMP_LTZdirectly.Dependency fix (
pyproject.toml/poetry.lock)snowflake-connector-python[secure-local-storage](pulls inkeyring) to silence the “keyring not installed” warning on every Snowflake connection. Purely additive lock change.Tests
tests/test_proposers_uuid.py, plus added coverage intests/test_make.py.