Help Getting an error "invalid keyword argument for this function"

1,689 views
Skip to first unread message

Karthik Krishnan

unread,
Oct 2, 2008, 2:26:55 PM10/2/08
to Django users
I have the following table in models.py

class SiteAccessProcess(models.Model):
"""Object model mapping to the site_access_process table.

Each element in the class represents a table column.
"""
instance_id = models.DecimalField(
blank=False, max_digits=32, decimal_places=0,
help_text='Unique integer id')
active_status = models.CharField(
max_length=3, choices=YES_NO_CHOICES, blank=False,
help_text='Status indicate whether the site is active or not.')
revision_date = models.DateTimeField(blank=False,
help_text='Date of revision')
revision_owner = models.CharField(max_length=64, blank=False,
help_text='Revision owner')
site_network = models.ForeignKey('Site', to_field='network_id',
help_text='Site network id')
title = models.CharField(max_length=128, blank=False,
help_text='Site access process title'),
process = models.CharField(max_length=2048, blank=False,
help_text='Site access process details'),
access_request_lead_time = models.DecimalField(
max_digits=32, decimal_places=0,
help_text='In hours. How many hours in advance you have to
request '
'access [24, 48, 72 hours].')
tracking_id = models.DecimalField(
blank=False, max_digits=16, decimal_places=0,
help_text='tracking number to avoid concurrency issues. Default
to 1. '
'Increment on update/delete. Will Not be visible to the users')


I am running a unit test.

def test_site_access_process_initialization(self):
site_access_process = models.SiteAccessProcess(
instance_id = 970334,
revision_date = datetime.datetime(2008,8,4,12,30,45),
revision_owner= 'kartik', site_network_id =
self.site.network_id,
title='SWE', process="Some arbitrary process",
access_request_lead_time=300)
self.failIfEqual(site_access_process, None,
"Failure to initialize site access process")

I get the following error.

265, in __init__
raise TypeError, "'%s' is an invalid keyword argument for this
function" % kwargs.keys()[0]
TypeError: 'title' is an invalid keyword argument for this function


I have tried to set title = "SWE" with a double quote as well as
title='SWE' with a single quote. But nothing seems to be working.
Can anybody please help?

Malcolm Tredinnick

unread,
Oct 2, 2008, 11:57:32 PM10/2/08
to django...@googlegroups.com

On Thu, 2008-10-02 at 11:26 -0700, Karthik Krishnan wrote:
> I have the following table in models.py
>
> class SiteAccessProcess(models.Model):
[... snip ...]

> I am running a unit test.

[...]

> I get the following error.
>
> 265, in __init__
> raise TypeError, "'%s' is an invalid keyword argument for this
> function" % kwargs.keys()[0]
> TypeError: 'title' is an invalid keyword argument for this function
>
>
> I have tried to set title = "SWE" with a double quote as well as
> title='SWE' with a single quote. But nothing seems to be working.
> Can anybody please help?

Try trimming down your model as much as possible by removing columns
apart from title. Then, when the error goes away, reintroduce them
slowly (this will require continually calling "django-admin.py reset
<app_name>", but it's just for debugging this case).

There are a bunch of syntax errors (missing trailing commas) in the
model code you posted, so that's not the code you are really running.
There's also so much of it that it's difficult to work out what the
relevant bits are. So, again, trimming down to the smallest possible
example that fails will no doubt help us and you see where the problem
is a lot more easily. It looks on the surface like your code should work
fine, so it's going to be something like a syntax error or a missing
parenthesis or similar. Thus, trimming the fat will help narrow down the
problem.

Regards,
Malcolm


Karen Tracey

unread,
Oct 3, 2008, 12:08:05 AM10/3/08
to django...@googlegroups.com

This is hard to parse in email, a better place for this amount of code is someplace like dpaste.com where it can be formatted properly.  Nevertheless the problem appears to be the trailing commas you have on the title and process field definitions.  It isn't immediately apparent to me why, but this seems to make those fields invisible -- there are no columns for them created in the database table and as you see you get an error trying to specify one of them.

This can be replicated with a much simpler model:

class Site(models.Model):
    name = models.CharField(max_length=8),
    network_id = models.AutoField(primary_key=True)

manage.py syncdb on this will create a table with just the 'network_id' column.  Removing the comma and running manage py reset <app> creates a table with both 'name' and 'network_id' columns.  Probably it's an extremely obvious Python thing that I'm missing because it's really too late for me to be trying to read code...

Karen
Reply all
Reply to author
Forward
0 new messages