Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
deleted 6 characters in body
Source Link
Maciej Gol
  • 15.9k
  • 4
  • 35
  • 52

The error is caused by the user.user_info.save() line has thrownthrowing an errorexception, and the transaction has beenwas flagged as broken (PostgreSQL enforces rolling back either the whole transaction, or to any savepoint stored before doing any more queries in theinside that transaction).

You can rollback the transaction when an error occurs like so:

from django.db import IntegrityError, transaction @receiver(post_save, sender=User) def saveUserAndInfo(sender, instance, **kwargs): user = instance try: with transaction.atomic(): user.user_info.save() except IntegrityError: info = UserInfo() info.user = user info.save() 

This is greatly described in the documentation.

Also, note that catching all exception types is not generally the best idea as you might silence exceptions you weren't expecting.

The error is caused by the user.user_info.save() line has thrown an error, and the transaction has been flagged as broken (PostgreSQL enforces rolling back either the whole transaction, or to any savepoint stored before doing any more queries in the transaction).

You can rollback the transaction when an error occurs like so:

from django.db import IntegrityError, transaction @receiver(post_save, sender=User) def saveUserAndInfo(sender, instance, **kwargs): user = instance try: with transaction.atomic(): user.user_info.save() except IntegrityError: info = UserInfo() info.user = user info.save() 

This is greatly described in the documentation.

Also, note that catching all exception types is not generally the best idea as you might silence exceptions you weren't expecting.

The error is caused by the user.user_info.save() line throwing an exception, and the transaction was flagged as broken (PostgreSQL enforces rolling back either the whole transaction, or to any savepoint stored before doing any more queries inside that transaction).

You can rollback the transaction when an error occurs:

from django.db import IntegrityError, transaction @receiver(post_save, sender=User) def saveUserAndInfo(sender, instance, **kwargs): user = instance try: with transaction.atomic(): user.user_info.save() except IntegrityError: info = UserInfo() info.user = user info.save() 

This is greatly described in the documentation.

Also, note that catching all exception types is not generally the best idea as you might silence exceptions you weren't expecting.

added 8 characters in body
Source Link
Maciej Gol
  • 15.9k
  • 4
  • 35
  • 52

The error is caused by the user.user_info.save() line has thrown an error, and the transaction has been flagged as broken (PostgreSQL enforces rolling back either the whole transaction, or to any savepoint stored before doing any more queries in the transaction).

You can rollback the transaction when an error occurs like so:

from django.db import IntegrityError, transaction @receiver(post_save, sender=User) def saveUserAndInfo(sender, instance, **kwargs): user = instance try: with transaction.atomic(): user.user_info.save() except IntegrityError: info = UserInfo() info.user = user info.save() 

This is greatly described in the documentation.

Also, note that catching all exception types is not generally the best idea as you might silence exceptions you weren't expecting.

The error is caused by the user.user_info.save() line has thrown an error, and the transaction has been flagged as broken (PostgreSQL enforces rolling back the whole transaction or to any savepoint stored before doing any more queries in the transaction).

You can rollback the transaction when an error occurs like so:

from django.db import IntegrityError, transaction @receiver(post_save, sender=User) def saveUserAndInfo(sender, instance, **kwargs): user = instance try: with transaction.atomic(): user.user_info.save() except IntegrityError: info = UserInfo() info.user = user info.save() 

This is greatly described in the documentation.

Also, note that catching all exception types is not generally the best idea as you might silence exceptions you weren't expecting.

The error is caused by the user.user_info.save() line has thrown an error, and the transaction has been flagged as broken (PostgreSQL enforces rolling back either the whole transaction, or to any savepoint stored before doing any more queries in the transaction).

You can rollback the transaction when an error occurs like so:

from django.db import IntegrityError, transaction @receiver(post_save, sender=User) def saveUserAndInfo(sender, instance, **kwargs): user = instance try: with transaction.atomic(): user.user_info.save() except IntegrityError: info = UserInfo() info.user = user info.save() 

This is greatly described in the documentation.

Also, note that catching all exception types is not generally the best idea as you might silence exceptions you weren't expecting.

Source Link
Maciej Gol
  • 15.9k
  • 4
  • 35
  • 52

The error is caused by the user.user_info.save() line has thrown an error, and the transaction has been flagged as broken (PostgreSQL enforces rolling back the whole transaction or to any savepoint stored before doing any more queries in the transaction).

You can rollback the transaction when an error occurs like so:

from django.db import IntegrityError, transaction @receiver(post_save, sender=User) def saveUserAndInfo(sender, instance, **kwargs): user = instance try: with transaction.atomic(): user.user_info.save() except IntegrityError: info = UserInfo() info.user = user info.save() 

This is greatly described in the documentation.

Also, note that catching all exception types is not generally the best idea as you might silence exceptions you weren't expecting.