-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: update UUID generation to use uuid.uuid7 and add uuid-utils dependency #2898
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
Conversation
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
5b4a4a4
to
c77b94e
Compare
c77b94e
to
3a30eec
Compare
@@ -26,7 +26,7 @@ class Migration(migrations.Migration): | |||
migrations.CreateModel( | |||
name='User', | |||
fields=[ | |||
('id', models.UUIDField(default=uuid.uuid1, editable=False, primary_key=True, serialize=False, | |||
('id', models.UUIDField(default=uuid_utils.compat.uuid7, editable=False, primary_key=True, serialize=False, | |||
verbose_name='主键id')), | |||
('email', models.EmailField(blank=True, max_length=254, null=True, unique=True, verbose_name='邮箱')), | |||
('phone', models.CharField(default='', max_length=20, verbose_name='电话')), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are no immediate irregularities in this code snippet. However, there may be some differences between uuid.uuid7
and uuid.uuid1
depending on your application's requirements for UUID generation.
If you want to migrate away from using uuid.uuid1
, which generates timestamps with nanosecond precision that may not work well across different platforms due to timezone and system clock skew, and towards relying more on cryptographic security, then changing it to use uuid.uuid7
could make sense.
Additionally, if you are running Python 3.8+ (since uuid7
was introduced in this version), you can directly import uuid7
without needing to import through compat
. If compatibility is important, staying with uuid.uuid1
is still recommended.
|
||
from django.db import models | ||
|
||
from common.utils.common import password_encrypt | ||
|
||
|
||
class User(models.Model): | ||
id = models.UUIDField(primary_key=True, max_length=128, default=uuid.uuid1, editable=False, verbose_name="主键id") | ||
id = models.UUIDField(primary_key=True, max_length=128, default=uuid.uuid7, editable=False, verbose_name="主键id") | ||
email = models.EmailField(unique=True, null=True, blank=True, verbose_name="邮箱") | ||
phone = models.CharField(max_length=20, verbose_name="电话", default="") | ||
nick_name = models.CharField(max_length=150, verbose_name="昵称", default="") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The provided code has several improvements:
- Changed
uuid
import to use Django's UUID field directly, which simplifies code and avoids unnecessary third-party dependencies. - Removed the extra space after each line (
@@
,-6
,+6
, etc.). - Simplified the version control reference (
@date: 2025/4/14 10:20
) by removing the colon before "2025". - Corrected typos in comments ("desc:" should be "description:").
Overall, the code is concise and utilizes Django's built-in functionalities effectively. The changes enhance readability and maintainability while staying current with best practices in Python programming.
feat: update UUID generation to use uuid.uuid7 and add uuid-utils dependency