-
Notifications
You must be signed in to change notification settings - Fork 128
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
UniqueViolation when loading data (loaddata with a fixture) #262
Comments
hi, After following the installation instructions provided, and figuring out my first error (#261), i loaded the example fixtures and received this error msg: Reverse for 'forum' with arguments '('a-simple-sub-forum-1', Hashid(3): qz0m9d5wd3rx1)' not found. 1 pattern(s) tried: ['forum/forum/(?P[^/]+)\-(?P[0-9]+)/\Z'] In fact, without more detailed documentation, i've been getting errors since the installation. One thing that threw me was the fact that i had to be logged in just to see the index page (issue #261). Is there some way of resolving the 'reverse' error and is there an 'anonymous user' setting for the default page? thanks in advance |
@mronoffon |
@mtueng |
Fix #262 - Disable pre_save receivers during loaddata of fixtures
I noticed this bug during a database migration from mariadb to postgresql where I used dumpdata/loaddata.
The loaddata failed with this error:
<class 'psycopg2.errors.UniqueViolation'>: duplicate key value violates unique constraint "forum_member_forumprofile_user_id_key" DETAIL: Key (user_id)=(1743) already exists.
I found out that this is the SQL query that triggered the error:
INSERT INTO "forum_member_forumprofile" ("id", "user_id", "avatar", "signature", "posts_count", "_signature_rendered") VALUES (%s, %s, %s, %s, %s, %s)" % (1, 1743, '', '***', 1, '***')
The root cause is that a pre_save hook in machina/apps/forum_member/receivers.py already does a
get_or_create
, which triggered this SQL query to be executed before the one above:INSERT INTO "forum_member_forumprofile" ("user_id", "avatar", "signature", "posts_count", "_signature_rendered") VALUES (%s, %s, %s, %s, %s) RETURNING "forum_member_forumprofile"."id" % (1743, '', None, 0, None)
Long story short: This can be fixed by disabling the pre_save hooks when loading data (i.e. when
kwargs['raw'] == True
). I will create a pull request.Using:
The text was updated successfully, but these errors were encountered: