Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError 'company_id' is an invalid keyword argument for this function #1

Closed
denever opened this issue Apr 20, 2012 · 5 comments
Closed

Comments

@denever
Copy link

denever commented Apr 20, 2012

I get this error here:

def create_historical_record(self, instance, type):
...
    manager.create(history_type=type, changed_by=changed_by, **attrs)
....

My Model is:

class Department(models.Model):
    company = models.ForeignKey(Company, verbose_name=_('Company'))
    name = models.CharField(_('Department name'), max_length=200)
    description = models.TextField(_('Department description'))
    size = models.PositiveIntegerField('Department size mq.')

    history = HistoricalRecords()

Where am I wrong?

Thank you

@treyhunner
Copy link
Member

I can't tell what the error might be without a line number of the error or a traceback. Does this only happen on this one model?

@jscheinblum
Copy link

This might be a Django 1.4 issue. I saw the same thing running through the README Polls, Choices example:

n [2]: from changes.models import Poll, Choice

In [3]: Poll.objects.all()
Out[3]: []

In [4]: import datetime

In [5]: p = Poll(question="what's up?", pub_date=datetime.datetime.now())

In [6]: p.save()
/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py:808: RuntimeWarning: DateTimeField received a naive datetime (2012-05-03 19:05:06.616432) while time zone support is active.
  RuntimeWarning)
/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py:808: RuntimeWarning: DateTimeField received a naive datetime (2012-05-03 19:05:09.144733) while time zone support is active.
  RuntimeWarning)

In [7]: p.history.all()
Out[7]: [<HistoricalPoll: Poll object as of 2012-05-04 00:05:09.144733+00:00>]

In [8]: p.pub_date = datetime.datetime(2007,4,1,0,0)

In [9]: p.save()
/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py:808: RuntimeWarning: DateTimeField received a naive datetime (2007-04-01 00:00:00) while time zone support is active.
  RuntimeWarning)
/usr/local/lib/python2.7/dist-packages/django/db/models/fields/__init__.py:808: RuntimeWarning: DateTimeField received a naive datetime (2012-05-03 19:05:23.245754) while time zone support is active.
  RuntimeWarning)

In [10]: p.history.all()
Out[10]: [<HistoricalPoll: Poll object as of 2012-05-04 00:05:23.245754+00:00>, <HistoricalPoll: Poll object as of 2012-05-04 00:05:09.144733+00:00>]

In [11]: p.choice_set.create(choice='Not Much', votes=0)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/usr/local/lib/python2.7/dist-packages/django/core/management/commands/shell.pyc in <module>()
----> 1 p.choice_set.create(choice='Not Much', votes=0)

/usr/local/lib/python2.7/dist-packages/django/db/models/fields/related.pyc in create(self, **kwargs)
    483                 kwargs[rel_field.name] = self.instance
    484                 db = router.db_for_write(self.model, instance=self.instance)
--> 485                 return super(RelatedManager, self.db_manager(db)).create(**kwargs)
    486             create.alters_data = True
    487 

/usr/local/lib/python2.7/dist-packages/django/db/models/manager.pyc in create(self, **kwargs)
    135 
    136     def create(self, **kwargs):
--> 137         return self.get_query_set().create(**kwargs)
    138 
    139     def bulk_create(self, *args, **kwargs):

/usr/local/lib/python2.7/dist-packages/django/db/models/query.pyc in create(self, **kwargs)
    375         obj = self.model(**kwargs)
    376         self._for_write = True
--> 377         obj.save(force_insert=True, using=self.db)
    378         return obj
    379 

/usr/local/lib/python2.7/dist-packages/django/db/models/base.pyc in save(self, force_insert, force_update, using)
    461         if force_insert and force_update:
    462             raise ValueError("Cannot force both insert and updating in model saving.")
--> 463         self.save_base(using=using, force_insert=force_insert, force_update=force_update)
    464 
    465     save.alters_data = True

/usr/local/lib/python2.7/dist-packages/django/db/models/base.pyc in save_base(self, raw, cls, origin, force_insert, force_update, using)
    563         if origin and not meta.auto_created:
    564             signals.post_save.send(sender=origin, instance=self,
--> 565                 created=(not record_exists), raw=raw, using=using)
    566 
    567 

/usr/local/lib/python2.7/dist-packages/django/dispatch/dispatcher.pyc in send(self, sender, **named)
    170 
    171         for receiver in self._live_receivers(_make_id(sender)):
--> 172             response = receiver(signal=self, sender=sender, **named)
    173             responses.append((receiver, response))
    174         return responses

/usr/local/lib/python2.7/dist-packages/simple_history/models.pyc in post_save(self, instance, created, **kwargs)
    136 
    137     def post_save(self, instance, created, **kwargs):
--> 138         self.create_historical_record(instance, created and '+' or '~')
    139 
    140     def post_delete(self, instance, **kwargs):

/usr/local/lib/python2.7/dist-packages/simple_history/models.pyc in create_historical_record(self, instance, type)
    147         for field in instance._meta.fields:
    148             attrs[field.attname] = getattr(instance, field.attname)
--> 149         manager.create(history_type=type, changed_by=changed_by, **attrs)
    150 
    151 class HistoricalObjectDescriptor(object):

/usr/local/lib/python2.7/dist-packages/django/db/models/manager.pyc in create(self, **kwargs)
    135 
    136     def create(self, **kwargs):
--> 137         return self.get_query_set().create(**kwargs)
    138 
    139     def bulk_create(self, *args, **kwargs):

/usr/local/lib/python2.7/dist-packages/django/db/models/query.pyc in create(self, **kwargs)
    373         and returning the created object.
    374         """
--> 375         obj = self.model(**kwargs)
    376         self._for_write = True
    377         obj.save(force_insert=True, using=self.db)

/usr/local/lib/python2.7/dist-packages/django/db/models/base.pyc in __init__(self, *args, **kwargs)
    365                     pass
    366             if kwargs:
--> 367                 raise TypeError("'%s' is an invalid keyword argument for this function" % kwargs.keys()[0])
    368         super(Model, self).__init__()
    369         signals.post_init.send(sender=self.__class__, instance=self)

TypeError: 'poll_id' is an invalid keyword argument for this function

@treyhunner
Copy link
Member

Should be resolved by 574e2ef.

macro1 pushed a commit that referenced this issue Mar 19, 2016
@kazgm
Copy link

kazgm commented May 5, 2019

Products.objects.create(title="New product 2", descriptions="another one", price="12300", summary="sweet")
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\kazgm\Dev\kazhome\lib\site-packages\django\db\models\manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\kazgm\Dev\kazhome\lib\site-packages\django\db\models\query.py", line 415, in create
obj = self.model(**kwargs)
File "C:\Users\kazgm\Dev\kazhome\lib\site-packages\django\db\models\base.py", line 495, in init
raise TypeError("'%s' is an invalid keyword argument for this function" % kwarg)
TypeError: 'title' is an invalid keyword argument for this function
Pls i need help on this error.

@macro1
Copy link
Collaborator

macro1 commented May 5, 2019

@kazgm: I don't see simple_history anywhere in your traceback. I don't think your issue has anything to do with this library.
Here is the Django documentation for create:
https://docs.djangoproject.com/en/2.2/ref/models/querysets/#create

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants