Re: save() got an unexpected keyword argument 'force_insert'

1,426 views
Skip to first unread message

Joel Goldstick

unread,
Sep 24, 2012, 11:59:48 AM9/24/12
to django...@googlegroups.com
On Mon, Sep 24, 2012 at 12:51 AM, Laxmikant Gurnalkar
<laxmikant...@gmail.com> wrote:
>
> Hi guys,
> Anybody knows why I'm at this stage ?
> Group.objects.using('db2').get_or_create(name='Maintenance Admin')
> Traceback (most recent call last):
> File "<console>", line 1, in <module>
> File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line
> 383, in get_or_create
> obj.save(force_insert=True, using=self.db)
> TypeError: save() got an unexpected keyword argument 'force_insert'
>
>
> I'm getting this error on creating a new group on mydatabase2
> Not getting the exact reason behind this ...
> plz help ...
>
> Thanks in Advance
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/django-users/-/4Rosfupipe4J.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

This is the first google entry for your error message:

https://code.djangoproject.com/ticket/8662

It looks like the docs were wrong, but they have been fixed.

--
Joel Goldstick

Laxmikant Gurnalkar

unread,
Sep 25, 2012, 2:19:56 AM9/25/12
to django...@googlegroups.com

Thanks Joel,
This makes sense to me.Still I could not resolve this.
Still on updating my save method, 
Like this
     super(model, self).save(force_insert=True)
giving an error. 

User.objects.get(id = userid) File "/usr/lib/python2.6/site-packages/django/db/models/manager.py", line 132, in get return self.get_query_set().get(*args, **kwargs) File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 342, in get num = len(clone) File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 80, in __len__ self._result_cache = list(self.iterator()) File "/usr/lib/python2.6/site-packages/django/db/models/query.py", line 271, in iterator for row in compiler.results_iter(): File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 677, in results_iter for rows in self.execute_sql(MULTI): File "/usr/lib/python2.6/site-packages/django/db/models/sql/compiler.py", line 732, in execute_sql cursor.execute(sql, params) File "/usr/lib/python2.6/site-packages/django/db/backends/util.py", line 15, in execute return self.cursor.execute(sql, params) File "/usr/lib/python2.6/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 44, in execute return self.cursor.execute(query, args) DatabaseError: current transaction is aborted, commands ignored until end of transaction block

Thakns in advance,
-Laxmikant
--
GlxGuru

Dan Gentry

unread,
Sep 25, 2012, 11:20:54 AM9/25/12
to django...@googlegroups.com
To address the original question, I saw a similar error when overriding the save() function of a model.  The solution was to include *args and **kwargs in the function definition:

    def save(self,*args, **kwargs):
        # your custom code here #
        super(MyModel, self).save(*args, **kwargs)


Laxmikant Gurnalkar

unread,
Sep 26, 2012, 12:22:07 AM9/26/12
to django...@googlegroups.com
Dan,
Thanks, This worked well for me.
I had missed to pass arguments to my save method.
i.e. I had like this
     def save(self,):
          args = ()
          kwargs['force_insert'] = True,
          kwargs['force_insert'] = False
          super(MyModel, self).save(*args, **kwargs)
Anyways.
I'm not so expert in python.
Thanks guys again

regards
Laxmikant Gurnalkar


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/vYCgvZ74BEQJ.
Reply all
Reply to author
Forward
0 new messages