question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

different exception type

See original GitHub issue

hi with postgres database connection, exception raised as psycopg2.IntegrityError but its not same as peewee.IntegrityError and not catchable. it is normal to use psycopg2.IntegrityError in except ? for example:

try:
    model.save()
except psycopg2.IntegrityError:
    raise

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
coleifercommented, Mar 7, 2018

If you are using Postgres, you need to take care that, if you get the connection into a bad state – i.e., by an IntegrityError – you need to rollback. Auto-rollback will issue the rollback automatically, but it’s better, in my opinion, to manage the transaction yourself:

try:
    with db.atomic():
        some_obj.save()
except peewee.IntegrityError:
    # do something else?
0reactions
MR-omidcommented, Mar 6, 2018

hey, i tested again and its worked 😃 but if i set autorollback to false, problem will be appear.


Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 3830, in execute_sql
    cursor.execute(sql, params or ())
psycopg2.IntegrityError: duplicate key value violates unique constraint "core_config_attribute"
DETAIL:  Key (attribute)=(test) already exists.


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/dpe/workspace/python/F.SystemAPI/models/Config.py", line 31, in save_changes
    model.save()
  File "/usr/local/lib/python3.5/dist-packages/playhouse/signals.py", line 69, in save
    ret = super(Model, self).save(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 5170, in save
    pk_from_cursor = self.insert(**field_dict).execute()
  File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 3584, in execute
    cursor = self._execute()
  File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 2939, in _execute
    return self.database.execute_sql(sql, params, self.require_commit)
  File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 3837, in execute_sql
    self.commit()
  File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 3656, in __exit__
    reraise(new_type, new_type(*exc_args), traceback)
  File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 135, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 3830, in execute_sql
    cursor.execute(sql, params or ())
peewee.IntegrityError: duplicate key value violates unique constraint "core_config_attribute"
DETAIL:  Key (attribute)=(test) already exists.


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 3830, in execute_sql
    cursor.execute(sql, params or ())
psycopg2.InternalError: current transaction is aborted, commands ignored until end of transaction block


During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/dpe/workspace/python/F.SystemAPI/dev.py", line 18, in <module>
    server.start()
  File "/home/dpe/workspace/python/F.SystemAPI/core/Server.py", line 36, in start
    Config.save_changes([{'attribute':'test','value':'omid'},{'attribute':'test2','value':'omid'},{'attribute':'test','value':'omid3'}])
  File "/home/dpe/workspace/python/F.SystemAPI/models/Config.py", line 35, in save_changes
    model = Config.get(attribute=config['attribute'])
  File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 4988, in get
    return sq.get()
  File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 3220, in get
    return next(clone.execute())
  File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 3274, in execute
    self._qr = ResultWrapper(model_class, self._execute(), query_meta)
  File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 2939, in _execute
    return self.database.execute_sql(sql, params, self.require_commit)
  File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 3837, in execute_sql
    self.commit()
  File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 3656, in __exit__
    reraise(new_type, new_type(*exc_args), traceback)
  File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 135, in reraise
    raise value.with_traceback(tb)
  File "/usr/local/lib/python3.5/dist-packages/peewee.py", line 3830, in execute_sql
    cursor.execute(sql, params or ())
peewee.InternalError: current transaction is aborted, commands ignored until end of transaction block
Read more comments on GitHub >

github_iconTop Results From Across the Web

Types of Exception in Java with Examples - GeeksforGeeks
Built-in Exceptions: · ArithmeticException: It is thrown when an exceptional condition has occurred in an arithmetic operation.
Read more >
Types of Exceptions in Java - Stackify
Exceptions are the unwanted errors or bugs or events that restrict the normal execution of a program. Each time an exception occurs, program ......
Read more >
What are different types of exceptions in Java? - Educative.io
The Throwable class is the superclass of all exceptions and errors in Java. All other exception classes are subclasses of the Throwable.
Read more >
Types of Exceptions - w3resource
All exception types are subclasses of the built-in class Throwable. Thus, Throwable is at the top of the exception class hierarchy. Immediately ...
Read more >
Exception Handling in Java - Javatpoint
Advantage of Exception Handling · Types of Java Exceptions · 1) Checked Exception · 2) Unchecked Exception · 3) Error · 1) A...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found