I’m trying to save my model form. Django reurns InternalError: current transaction is aborted, commands ignored until end of transaction block
This is a problem in executing INSERT sql-query which is generated by Django. It looks like:
INSERT INTO "myapp_mymodel" ("title", ...) VALUES ("Test", ...) RETURNING "catalog_ad"."id"; args=("title", ...)
I tried to execute this query in PgAdmin. It returned this error:
ERROR: syntax error at or near "args"
What can be wrong?
UPD: Here is tracback for InternalError:
File "/Library/Python/2.7/site-packages/django/core/handlers/base.py" in get_response
111. response = callback(request, *callback_args, **callback_kwargs)
File "/<Path to my app>/views.py" in master
115. ad = form.save()
File "/Library/Python/2.7/site-packages/django/forms/models.py" in save
364. fail_message, commit, construct=False)
File "/Library/Python/2.7/site-packages/django/forms/models.py" in save_instance
86. instance.save()
File "<Path to my app>/models.py" in save
145. super(Ad, self).save(*args, **kwargs)
File "/Library/Python/2.7/site-packages/django/db/models/base.py" in save
463. self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/Library/Python/2.7/site-packages/django/db/models/base.py" in save_base
551. result = manager._insert([self], fields=fields, return_id=update_pk, using=using, raw=raw)
File "/Library/Python/2.7/site-packages/django/db/models/manager.py" in _insert
203. return insert_query(self.model, objs, fields, **kwargs)
File "/Library/Python/2.7/site-packages/django/db/models/query.py" in insert_query
1576. return query.get_compiler(using=using).execute_sql(return_id)
File "/Library/Python/2.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
910. cursor.execute(sql, params)
UPD2:
My model has overwrited save method:
def save(self, *args, **kwargs):
self.title = self.model.brand.name + " " + self.model.name
super(Ad, self).save(*args, **kwargs)
Data is proccessed by view which uses ModelForm (which gets data from POST). Form was validated (form.is_valid()) before saving.
I would say that you’ve got a bug in your code that generates the INSERT statement through Django. It’s hard to say what the problem is without seeing that code. The semicolon in the SQL you posted ends a valid-looking SQL statement.
The
args=("title", ...)portion doesn’t look SQL to me. Check your code to see what might be accidentally appending that to whatever generates the SQL.