-
-
Notifications
You must be signed in to change notification settings - Fork 30.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFE] fields
and time_*
properties must not be used on UUIDs that are time-agnostic.
#120878
Comments
@Eclips4 I don't know who to ask, but I know that you're a triager so I'm wondering if you know who should be the person to ask on that topic. |
https://devguide.python.org/core-developers/experts/ is states that uuid doesn't have an expert :( |
My first take on this: It is (1) a feature request. It is also (2) a clarification of the existing API and how it should be used, on the existing already supported UUID v1-5 types vs on proposed newly added support for v6-8. We're split across this issue and the already linked #89083 for this overall topic. I agree that the We cannot change the numeric indices of things in It may not make sense to bother with a deprecation though if maintaining their existing behavior and documenting when they should or shouldn't be used is enough. (ie: do we have evidence of their existence on irrelevant UUID versions as causing people to write buggy code? If so, deprecating them would help guide our users away from bugs!)
The old tuple accesses are effectively a legacy of old-style Python API design as the So given that... We should ask ourselves if a How often does code need to accept arbitrary UUIDs of all possible versions at once? I'd expect most applications to only ever be dealing with a single known UUID type, or perhaps two. I am decidedly not a UUID expert. I'm just playing one on TV. :P |
Oups, sorry my bad for the incorrect category!
Definitely. I know that UUIDs can be used for long-standing preservation so if we change the semantics, we could break applications.
That I cannot say. An UUID object is opaque and I can only hope that people will use it as a black box and not try to do black magic except for tests. The only field I'd expect them to use publicly and reliably is the
If I could have the final say, I'd hope not to have them! It's useless for constructing them from fields and it's incorrect to use the corresponding properties (the semantics don't match!).
Well.. it depends on the implementation. v7 and v8 can be made time-agnostic or not.
Actually, an UUID is independent of its version and its ABNF is:
I think the reason why they were separated as such is historically based on UUIDv1 where the ABNF fields match the UUIDv1 fields and properties (the first four octets are Ideally, fields should be version-agnostic and In summary, I think fields should not be modified at all, even for future UUIDs. They should always reflect the UUID's URN I think. I'll revert the commits that touched the properties and adapt the test. It'll be easier to review and less prone to errors. For the other properties, I still don't know what to do with them... |
fields
and time_*
properties must not be used on UUIDs that are time-agnostic.fields
and time_*
properties must not be used on UUIDs that are time-agnostic.
I'm also not a UUID expert, but I suggest: Right now, just add new constructor functions. Don't change the class, don't deprecate existing fields or add new ones. In another PR, document how the field names are misleading. A docs-only PR can be backported to 3.13 and 3.12. Then let's get back to this issue. |
I like that plan. So this specific issue will be stalled until the other one is resolved. However, for the other one, we still need to decide which implementation to go for. |
Hello, RFC 9562 author here. Generally I agree with @encukou's approach. I vote to leave Then later, take more modern approach like a Edit:
I had a small blurb in a section that follows your line of thinking: https://www.rfc-editor.org/rfc/rfc9562.html#name-opacity |
Currently, the
uuid.UUID
class features afields
argument and property which is a six-tuple of integers:time_low
,time_mid
,time_hi_version
,clock_seq_hi_variant
,clock_seq_low
,node
.Currently, those fields are only relevant when the UUID version is 1 since UUIDv3 and UUIDv5 are based on MD5 and SHA-1 respectively instead. However, the recent RFC 9562, superseeding RFC 4122, introduces one time-based UUID, namely UUIDv6 (basde on UNIX epoch instead of Gregorian epoch, and with timestamp bits ordered differently), as well as UUIDv7 and UUIDv8 that are implementation details.
Here is what we can do for now:
With the addition of those variants, we at least have one UUID distinct from UUIDv1 featuring time-related fields. In particular, it is important to decide whether
fields[0]
is the first RFC field in the UUID or if this is always the first 32-bit fields. I personally think that we should say that fields represents the RFC fields, namely,fields[0]
is a 32-bit integer corresponding to the 32 LSB (resp. MSB) of the 60-bit timestamp for UUIDv1 (resp. UUIDv6).For UUIDv7, if we choose sub-ms precision, then the fields are a bit different in the sense that we now have
unix_ts_ms (48) | ver (4) | subsec_a (12) | var (2) | counter (62)
, so we should decide how to split those fields into 6 and whether it make sense to have the corresponding properties. A similar question arises for UUIDv8.While we could change the semantics of the fields and
time_*
properties, this could break applications that assume thatfields
are independent of the time (my understanding of fields is that it is independent of the time or the RFC and is only a way to partition the UUID's integral value into 32+16+16+8+8+48 bits, but such partitioning is only relevant for UUIDv1).Therefore, I really don't know how to deal with those time-based properties. I'd like to avoid breaking longstanding applications but at the same time I don't want a property to incorrectly reflect its value. If we don't change anything,
uuidv6.time_low
would actually return the 32 highest bits...EDIT: Should this actually be a PEP? because UUIDv7 and UUIDv8 are implementation-detail so maybe a PEP might be a good idea?
The text was updated successfully, but these errors were encountered: