derek-schaefer / django-json-field

Generic JSON model and form fields.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

TypeError: db_type() got multiple values for keyword argument 'connection'

anler opened this issue · comments

Hi, I had this error in Django 1.3 with djangotoolbox and AppEngine because inside JSONField.db_type you are not passing the 'connection' param as a keyword argument, here's a fragment of the stack-trace:

File "/.../django/db/models/base.py", line 462, in save
    self.save_base(using=using, force_insert=force_insert, force_update=force_update)
File "/.../django/db/models/base.py", line 573, in save_base
    result = manager._insert(values, return_id=update_pk, using=using)
File ".../django/db/models/manager.py", line 195, in _insert
    return insert_query(self.model, values, **kwargs)
File "/.../django/db/models/query.py", line 1438, in insert_query
    return query.get_compiler(using=using).execute_sql(return_id)
File "/.../dbindexer/compiler.py", line 38, in execute_sql
    return super(SQLInsertCompiler, self).execute_sql(return_id=return_id)
File ".../db/basecompiler.py", line 368, in execute_sql
    db_type = field.db_type(connection=self.connection)
File "/.../django/db/models/fields/subclassing.py", line 28, in inner
    return func(*args, **kwargs)
File "/.../json_field/fields.py", line 102, in db_type
    return super(JSONField, self).db_type(connection)
File "/.../django/db/models/fields/subclassing.py", line 28, in inner
    return func(*args, **kwargs)
File "/.../django/db/models/fields/subclassing.py", line 28, in inner
    return func(*args, **kwargs)

for some reason, inside subclassing.py, django 1.3 and djangotoolbox's indexer is messing with the connection param when calling the following function:

def call_with_connection(func):
    arg_names, varargs, varkwargs, defaults = getargspec(func)
    updated = ('connection' in arg_names or varkwargs)
    if not updated:
        warn("A Field class whose %s method hasn't been updated to take a "
            "`connection` argument." % func.__name__,
            DeprecationWarning, stacklevel=3)

    def inner(*args, **kwargs):
        if 'connection' not in kwargs:
            from django.db import connection
            kwargs['connection'] = connection
            warn("%s has been called without providing a connection argument. " %
                func.__name__, DeprecationWarning,
                stacklevel=2)
        if updated:
            return func(*args, **kwargs)
        if 'connection' in kwargs:
            del kwargs['connection']
        return func(*args, **kwargs)
    return inner

I fixed it using this diff but I haven't tested it with other versions

Sorry, I think this is more an issue with djangotoolbox

Not a problem, thanks for the report. I've changed the function to be version agnostic anyway, just in case.

I meet this problem again.
I'm using the version 1.3 and pymssql to connect with sqlserver.
It can create table but put errot when inert values...
as:TypeError: db_type() got multiple values for keyword argument 'connection'

my code is:
from Blog.models import *
import datetime

p = Person(p_date=datetime.datetime.now(),pid='003',name='summer',address='caidian',vince='hubei')
#p = Reporter(full_name='wuhan')
p.save()
#print Person.objects.all()