Hi,
I have python threaded application + Postgres. I am using Django's ORM
to save to Postgres..
I have concurrent save calls. Occasionally 2 threads save with the
same primary key which leads to an issue.
Postgres log:
ERROR: duplicate key value violates unique constraint "store_pkey"
STATEMENT: INSERT INTO "store" ("store_id", "address") VALUES
(E'HAN277', E'101 Ocean Street')
Code:
In the code I see an IntegrityError. I tried different ways to handle
this.
a.
try:
a.save()
except IntegrityError:
pass
This causes InternalError
b. Tried to do transaction roll back.. but not sure.. As far as I
understand you need to distinct save calls to have transactions
sid = transaction.savepoint()
try:
row.save()
except IntegrityError, e:
transaction.savepoint_rollback(sid)
pass
transaction.commit()
The first savepoint fails with
AttributeError: 'NoneType' object has no attribute 'cursor'
a. I read somewhere django is not 100% thread safe. Is it a good
choice in my usecase. I was already using Django for other application
and need an ORM.. So naturally I chose Django
b. How to handle this situation.. Any comments.
Thanks and regards,
Ramya
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---