-
-
Notifications
You must be signed in to change notification settings - Fork 185
uuid.get_node
is failing to find a stable identifier
#587
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
Comments
Digging into this with a debugger...
Then looking at the CPython source to try to discern the difference here... class SafeUUID:
safe = 0
unsafe = -1
unknown = None static PyObject *
py_uuid_generate_time_safe(PyObject *Py_UNUSED(context),
PyObject *Py_UNUSED(ignored))
{
uuid_t uuid;
#ifdef HAVE_UUID_GENERATE_TIME_SAFE
int res;
res = uuid_generate_time_safe(uuid);
return Py_BuildValue("y#i", (const char *) uuid, sizeof(uuid), res);
#elif defined(HAVE_UUID_CREATE)
uint32_t status;
uuid_create(&uuid, &status);
# if defined(HAVE_UUID_ENC_BE)
unsigned char buf[sizeof(uuid)];
uuid_enc_be(buf, &uuid);
return Py_BuildValue("y#i", buf, sizeof(uuid), (int) status);
# else
return Py_BuildValue("y#i", (const char *) &uuid, sizeof(uuid), (int) status);
# endif /* HAVE_UUID_CREATE */
#else /* HAVE_UUID_GENERATE_TIME_SAFE */
uuid_generate_time(uuid);
return Py_BuildValue("y#O", (const char *) uuid, sizeof(uuid), Py_None);
#endif /* HAVE_UUID_GENERATE_TIME_SAFE */
} |
It seems like HAVE_UUID_GENERATE_TIME_SAFE is set in our build but not the HomeBrew one (due to the |
This feels like a CPython bug/quirk. The code prefers obtaining a random time for the node value on Linux if a C function is available. It then falls back to trying to find an actual hardware value. Feels like the ordering is wrong. But this may have been a choice to favor performance or security or something. But it isn't documented inline in uuid.py. |
Ah, they extract the node from the UUID: def _unix_getnode():
"""Get the hardware address on Unix using the _uuid extension module."""
if _generate_time_safe:
uuid_time, _ = _generate_time_safe()
return UUID(bytes=uuid_time).node |
From my limited understanding of So could this issue be addressed by setting the value of those directives the same way Brew and Python.org do? |
As in, we have |
I'm not sure I understand the question, but it seems to me that the issue here is that python-build-standalone says the libraries whose presence govern the value of Now, do we know if they indeed aren't available? And would there be some way to make them available? Again, my understanding here is quite limited, so these may well be stupid questions :D |
One more data point: I just tried installing Python 3.13 with Pyenv and it behaves the same as Brew and Python.org. That is to say, this So the appropriate libraries that govern |
I think you have it backwards. Here's what I'm saying:
Our If it's not desirable for |
For reference, here's the libuuid we're using: python-build-standalone/pythonbuild/downloads.py Lines 379 to 387 in 186813f
For Homebrew Python, |
Ahh, that is so odd. Thanks for clarifying. |
Looking at a Linux container...
|
per https://packages.debian.org/bookworm/libpython3.11-stdlib it looks like they're using https://packages.debian.org/bookworm/libuuid1 which presumably has different behavior. |
It still seems vaguely wrong to depend on this to extract the MAC address, as the man page only says
|
Version 1 UUIDs encode the time and MAC address. I think what CPython is doing here is deferring to the external implementation of UUID so they don't have to think about resolving a MAC. This is reasonable behavior IMO. |
I briefly looked at switching to the
Except the documentation does not guarantee that the MAC address is used? If that was reliable, I imagine this would be working. Otherwise, yeah — I agree it seems nice to rely on that instead of the complicated fallback methods they have. |
The more I look at this the more it looks like a Python bug. So I filed one here. But I still wonder whether |
…#11138) ## Describe your changes Rename the new `stableRandomMachineId` to `machineIdV4` to make it clear (1) we can't rely on `machineIdV3`, and (2) `machineIdV4` is the right one to use. [Originally](b44df19) I avoided doing this because the goal is to keep both IDs side by side, since that will help debug things or even roll back in the future. But even if we name it `machineIdV4` nothing precludes us from keeping them side by side. In the meantime, we're also following bug reports astral-sh/python-build-standalone#587 and python/cpython#132710 , which might rehabilitate `machineIdV3`. ## GitHub Issue Link (if applicable) n/a ## Testing Plan - Explanation of why no additional tests are needed: this PR just renames variables. - ~~Unit Tests (JS and/or Python)~~ - ~~E2E Tests~~ - ~~Any manual testing needed?~~ --- **Contribution License Agreement** By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
https://docs.python.org/3/library/uuid.html#uuid.getnode
The text was updated successfully, but these errors were encountered: