-
Notifications
You must be signed in to change notification settings - Fork 182
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
Change "object_id" to be a "CharField" #138
Conversation
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.
Looks great! Just needs one small fix (change id
to pk
)
easyaudit/signals/model_signals.py
Outdated
else: | ||
# Query the object, see if it exists | ||
try: | ||
old_model = sender.objects.get(id=instance.pk) |
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.
Please change this to pk=instance.pk
I have primary keys not named id
so this throws an exception
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.
@steverecio updated
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.
LGTM - I have this code deployed on my project and it seems to work as intended.
One note after testing this a bit more. The
|
@steverecio I was seeing this as well with postgres, doesn't seem to be an issue with sqlite. The instance id is stripped before the transaction completes with latest postgres. Simple fix i think. |
- Uses the internal `_state` object
Oh that's a nice idea. We use the I/we need to first fix/address the breakage on the request event user signal before merging anything else. Then we can add a couple more things (nothing which breaks compatibility/super risky). This seems like a good candidate! |
@jheld I also don't love checking |
Excellent work with all of the test cases and test models. Comprehensive and pretty modular/DRY. This looks like a great candidate for |
Likely will release |
About ready to merge this! So Can you take a look over the comments/reviews once more to make sure all of those are answered/moot? |
@jheld That is correct I took a look again and everything seems good to go. The only thing that i'm not 100% certain of is if existing users of this app will have to do anything special after the schema migration is run, such as converting the integers to chars. |
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.
Can you remove the sqlite test db file?
@jsoa if I'm understanding your question, so long as they run migrations, they shouldn't have to do anything other than that. I'm happy to test on my local, too, next week. My project runs on the default configuration. |
Hello! Really excited to see this PR go in. I'm working on a Django project where we're using UUIDs as primary keys for our users and this PR resolves the issues I'm seeing. It seems like it's nearly there, so hope this can be merged soon! 👍 |
@jheld started testing the migration (manually). See PR description for details, still work in progress. we can add more DB versions and/or django versions if needed. |
@jsoa this looks really great. Thank you for running through some simple (but time consuming!) test cases. My project uses MySQL but if you think you'll have time to run through that on your end I'll wait til then. Let me know -- happy to follow the instructions you've laid out. |
@jheld done with my testing, everything seems good to go, with the minor note about django 1.11. It would be nice to get someone to run through just some of the manual tests that was run. Here is a docker-compose file i used for bootstrapping the DBs
Each DB has a different host port
After each django version check, we need to reset the containers, by # 'default': {
# 'ENGINE': 'django.db.backends.postgresql',
# 'NAME': 'ea',
# 'USER': 'ea',
# 'PASSWORD': 'ea',
# 'HOST': 'localhost',
# 'PORT': '54323'
# }
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'ea',
'USER': 'ea',
'PASSWORD': 'ea',
'HOST': '127.0.0.1',
'PORT': '33061'
} |
@jsoa excellent use for docker-compose. We don't support django 1.11 officially anymore. 2.0+ (and realistically other than travis tests passing, we really only need to be 2.2+). So while I agree 1.11 is odd, I will argue we should ignore the difference. I have no idea what has changed/subtly broken in our usage. |
The code in this change set migrates the current
CrudEvent.object_id
from anIntegerField
to aCharField
as a means to allow various objects with differentPK
types.This includes a change to the
model_signals
that query's for the object instead of looking for thePK
, this is because the commonUUIDField
as aPK
usually has adefault
, thereofrePK
would never be empty, even on creation.This also includes a bug fix for
post_delete
with thePK
not being available in thecrud_flow
closure. See #138 (comment)Fixes: #131
Fixes: #90
Django
3.0
UUIDField
BigAutoField
UUIDField
andBigAutoField
UUIDField
andBigAutoField
UUID
andBigInt
UUID
andBigInt
Deep dive
The main purpose of these tests is to ensure current users of this app, will not need worry about the migration that will change the type of
object_id
from integer to char. All the output below should be the same per test group, i.e. django version and db. If anything should be different, it will be noted below.All the test below will do the following
test_app/create_obj/
5 timestest_app/update_obj/?id=N
for the 5 items aboveint
and basic query worksstr
and the query still works and returns the same results, by passing it str and int versions.Current progress
Notes
CRUDEvent
objects (on master branch)