-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Cable post_save signal cause exception in loaddata management command #3016
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
Thanks for the report, I will try and reproduce it. However, it is worth noting we probably can't get rid of update_connected_endpoints as that updates connected interfaces on the interfaces table. |
No that is very true, but you do not need the signal to be emited during a |
I finished reviewing the dump data, and I agree, we don't need to include the signals (at all even). I am going to do this and stash it as a PR for @jeremystretch and @lampwins to review. |
This looks related to #3849, where the order in which the objects are exported prevents them from being cleanly imported. Unfortunately Django's |
Can confirm that this does appear to be resolved by #3849 going to close this one out. |
Environment
Background
Some background that will describe what we are doing and how we found this bug. At our production envrionment we do dumps of the data once a day for backup purposes. We use the djangos built-in
dumpdata
for this. It outputs a json file that we commit to git to see what data changes over time. We also use these snapshots as test data that we can load to test envrionment to build prod replicas and we subset this sometimes at our local dev machines to load and test features and data migrations before going into prod. We use the djangos built-inloaddata
to read the json backups back from file into the database.After we merged into our local fork and deployed a upgrade from 2.5.6 to 2.5.8 we started to see some error with
loaddata
where it would throw a exception when run. I dug around and thought it was a merge issue but i could not find any problems with the merge. So i dug into the data to sett if i could dig up the problem object and code. The problem object was identified and i tracked the problem to the root cause that was a signal that is emit onpost_save
on Cable object saves. This is the stack trace it outputhttps://gist.github.com/Grokzen/1bed27569b80cbe34b6522c7e9746db4
The important part is when the code enters into the signal
To reproduce this bug, i extracted and sanitized out all data from the json data dump into this minimal data dump that should trigger the bug. I got this bug to reproduce on a clean/unmodified 2.5.8 installation so i hope it can be replicated elsewhere.
Steps to Reproduce
python3 manage.py loaddata db-dump.json
to start loading the data into the databaseExpected Behavior
The data should be loaded by django into the database and usable w/o any exception thrown.
Observed Behavior
The exception as mentioned link above is thrown
When i PDB the exception i get the following from the signal frame
Possible solution
Since the problem is in the signal that is implemented here, this is not a django specific problem with dumpdata/loaddata per say as they perform and resolve issues as expected.
Django does implement a feature that when you run management commands, django will inject a kwarg
raw=True
into all signals that is emited during the run of management commands.The simplest solution would be to change it to the following
But a more useful solution would be to make a decorator for it like
then it can be reused if other signals show signs of the same problem and it is more explicit about it's purpose and what it does.
There might be a possible fix further down the stack, but i would argue that during loading of a datadump, the problem signal have no real need to run on each cable save as the data from the datadump is already in a good state.
Note
I can't say how we got the database to be in this state or the steps to really reproduce it from the GUI that would produce the same or a similar data dump file. All i could figure our from the person probably responsible was that he was trying to make patch panels work and he got the data to be in this state.
The text was updated successfully, but these errors were encountered: