Skip to content
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

2.0: Migration extras.0094 breaks when user created multiple notes on same object in a day #4081

Closed
jakubkrysl opened this issue Jul 10, 2023 · 4 comments
Assignees
Labels
type: bug Something isn't working as expected
Milestone

Comments

@jakubkrysl
Copy link

Environment

  • Nautobot version (Docker tag too if applicable): 2.0.0.beta2
  • Python version:
  • Database platform, version:
  • Middleware(s):

Steps to Reproduce

  1. Create 2 (or more) Notes in single day (same date) on same object with same user
  2. Run extras.0094 migration to remove slug from Notes

Note: the message on these notes can be different, it is not included in the new constraint unique_together={("assigned_object_type", "assigned_object_id", "user_name", "created")}

Expected Behavior

migration passes

Observed Behavior

  Applying extras.0094_remove_slugs...Traceback (most recent call last):                                                                                                                                           
  File "/usr/local/lib/python3.10/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)                                                              
  File "/usr/local/lib/python3.10/site-packages/django_prometheus/db/common.py", line 71, in execute
    return super().execute(*args, **kwargs)                                                              
psycopg2.errors.UniqueViolation: could not create unique index "extras_note_assigned_object_type_id__e1504524_uniq"
DETAIL:  Key (assigned_object_type_id, assigned_object_id, user_name, created)=(1, 258ccdb0-1b29-44aa-a4ba-6468281de6ad, test_user, 2022-09-02 00:00:00+00) is duplicated.
@glennmatthews
Copy link
Contributor

Thanks for the report!

@glennmatthews glennmatthews added the type: bug Something isn't working as expected label Jul 10, 2023
@glennmatthews glennmatthews added this to the v2.0.0 milestone Jul 10, 2023
@bryanculver
Copy link
Member

I suspect this is because pre-2.0 created was a Date field instead of Datetime.

@Thetacz would it be acceptable to create a random second/microsecond to add to the 00:00:00+00 (since we never had the exact time anyway) to ensure uniqueness?

@jakubkrysl
Copy link
Author

I suspect this is because pre-2.0 created was a Date field instead of Datetime.

@Thetacz would it be acceptable to create a random second/microsecond to add to the 00:00:00+00 (since we never had the exact time anyway) to ensure uniqueness?

I already fixed the issue in our data, so it should not apply to us. But generally speaking you can either go the easy way of creating random time OR extract the time from ObjectChange which got created with the Note :)
Or do both with the random time as fallback.

@glennmatthews
Copy link
Contributor

resolved by #4134.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug Something isn't working as expected
Projects
No open projects
Archived in project
Development

No branches or pull requests

4 participants