# Buggy code
def store_user_details(sender, user, request, **kwargs):
    """
    Stores user details on registration, here we rely on
    validation done by RegistrationForm.
    """
    user.first_name = request.POST["first_name"]
    user.last_name = request.POST["last_name"]
    user.save()


# Traceback (django.db.transaction.TransactionManagementError)
* Error running /home/victor/weblate-1.3-0/python/bin/python manage.py createadmin : Traceback (most recent call last):
File "manage.py", line 30, in <module>
execute_from_command_line(sys.argv)
File "/home/victor/weblate-1.3-0/apps/django/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/home/victor/weblate-1.3-0/apps/django/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/victor/weblate-1.3-0/apps/django/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/victor/weblate-1.3-0/apps/django/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/home/victor/weblate-1.3-0/apps/weblate/weblate/accounts/management/commands/createadmin.py", line 35, in handle
user = User.objects.create_user('admin', 'admin@example.com', 'admin')
File "/home/victor/weblate-1.3-0/apps/django/lib/python2.7/site-packages/django/contrib/auth/models.py", line 160, in create_user
user.save(using=self._db)
File "/home/victor/weblate-1.3-0/apps/django/lib/python2.7/site-packages/django/db/models/base.py", line 463, in save
self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/home/victor/weblate-1.3-0/apps/django/lib/python2.7/site-packages/django/db/models/base.py", line 565, in save_base
created=(not record_exists), raw=raw, using=using)
File "/home/victor/weblate-1.3-0/apps/django/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 172, in send
response = receiver(signal=self, sender=sender, **named)
File "/home/victor/weblate-1.3-0/apps/weblate/weblate/accounts/models.py", line 241, in create_profile_callback
transaction.commit()
File "/home/victor/weblate-1.3-0/apps/django/lib/python2.7/site-packages/django/db/transaction.py", line 138, in commit
connection.commit()
File "/home/victor/weblate-1.3-0/apps/django/lib/python2.7/site-packages/django/db/backends/__init__.py", line 224, in commit
self.set_clean()
File "/home/victor/weblate-1.3-0/apps/django/lib/python2.7/site-packages/django/db/backends/__init__.py", line 166, in set_clean
raise TransactionManagementError("This code isn't under transaction management")
django.db.transaction.TransactionManagementError: This code isn't under transaction management*

# Fixed code
def store_user_details(sender, user, request, **kwargs):
    """
    Stores user details on registration and creates user profile. We rely on
    validation done by RegistrationForm.
    """
    user.first_name = request.POST["first_name"]
    user.last_name = request.POST["last_name"]
    user.save()
    profile, newprofile = Profile.objects.get_or_create(user=user)