Nis Jørgensen wrote:
> Hello all
> 
> I am using Django 0.96 with postgresql 8.1 and psycopg2. The error
> handling does not work as I would expect it to. Specifically, anytime a
> database error occurs, all subsequent calls to the database fails with
> the error message "ProgrammingError: current transaction is aborted,
> commands ignored until end of transaction block".

That is how PostgreSQL works. Your only option at that point is to 
rollback and start again. Unless you change your isolation level.

> 
> This causes unittesting to break, since the tearDown will try to use the
> existing database connection, as well as giving me strange error
> messages at other times. You vcan see an example of the latter at the
> bottom of my mail.
> 
> I have found that I can eliminate the problem by substituting this line
>             self.connection.set_isolation_level(1) # make transactions
> transparent to all cursors

This will work fine.

Joshua D. Drake


> with this one
>             self.connection.set_isolation_level(0)
> in django/db/backends/postgresql_psycopg2/base.py
> 
> However, I am worried that whoever wrote that code did so for a reason ;-)
> 
> Can anyone tell me:
> 
> - If this is intended behavior or a bug.
> - If my change is likely to break anything, and if so, if there is
> another recommended solution
> 
> Yours,
> 
> u'Nis J\xf8rgensen'
> 
> Appendix:
> 
> As an example of the problem, see the following interactive session
> 
> ./manage.py shell
> Python 2.4.4 (#2, Apr  5 2007, 20:11:18)
> [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> (InteractiveConsole)
>>>> from spider.models import Language
>>>> Language.objects.create(isocode='xx')
> <Language: xx>
>>>> Language.objects.create(isocode='xx')
> Traceback (most recent call last):
>   File "<console>", line 1, in ?
>   File "/usr/lib/python2.4/site-packages/django/db/models/manager.py",
> line 79, in create
>     return self.get_query_set().create(**kwargs)
>   File "/usr/lib/python2.4/site-packages/django/db/models/query.py",
> line 262, in create
>     obj.save()
>   File "/usr/lib/python2.4/site-packages/django/db/models/base.py", line
> 238, in save
>     ','.join(placeholders)), db_values)
>   File "/usr/lib/python2.4/site-packages/django/db/backends/util.py",
> line 12, in execute
>     return self.cursor.execute(sql, params)
> IntegrityError: duplicate key violates unique constraint
> "spider_language_isocode_key"
>>>> Language.objects.create(isocode='yy')
> Traceback (most recent call last):
>   File "<console>", line 1, in ?
>   File "/usr/lib/python2.4/site-packages/django/db/models/manager.py",
> line 79, in create
>     return self.get_query_set().create(**kwargs)
>   File "/usr/lib/python2.4/site-packages/django/db/models/query.py",
> line 262, in create
>     obj.save()
>   File "/usr/lib/python2.4/site-packages/django/db/models/base.py", line
> 238, in save
>     ','.join(placeholders)), db_values)
>   File "/usr/lib/python2.4/site-packages/django/db/backends/util.py",
> line 12, in execute
>     return self.cursor.execute(sql, params)
> ProgrammingError: current transaction is aborted, commands ignored until
> end of transaction block
> 
> 
> 
> 
> > 


-- 

       === The PostgreSQL Company: Command Prompt, Inc. ===
Sales/Support: +1.503.667.4564 || 24x7/Emergency: +1.800.492.2240
Providing the most comprehensive  PostgreSQL solutions since 1997
              http://www.commandprompt.com/

Donate to the PostgreSQL Project: http://www.postgresql.org/about/donate
PostgreSQL Replication: http://www.commandprompt.com/products/



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to