Note that there are some explanatory texts on larger screens.

plurals
  1. POExplicit argument in signature does not work? Very odd
    primarykey
    data
    text
    <p>I'm trying to understand why explicitly specifying the signature arguments doesn't work, but just blindly doing an *args, **kwargs works! I really don't see much difference between the two?</p> <p>Example that does not work:</p> <pre><code>from django.db.models import CharField as _CharField class CharField(_CharField): def get_db_prep_value(self, value, connection, prepared=False): if self.blank == self.null == self.unique == True and value == '': value = None return super(CharField, self).get_db_prep_value(value, connection, prepared) # &lt;--- this does not work! </code></pre> <p>and I get the following error:</p> <pre><code> File "/home/googledroid/Workspace/eclipse/gameproject/virtualenv/lib/python2.6/site-packages/django/db/models/fields/__init__.py", line 276, in get_db_prep_save return self.get_db_prep_value(value, connection=connection, prepared=False) File "/home/googledroid/Workspace/eclipse/gameproject/virtualenv/lib/python2.6/site-packages/django/db/models/fields/subclassing.py", line 53, in inner return func(*args, **kwargs) File "/home/googledroid/Workspace/eclipse/gameproject/src/fields/__init__.py", line 13, in get_db_prep_value return super(CharField, self).get_db_prep_value(value, connection, prepared) File "/home/googledroid/Workspace/eclipse/gameproject/virtualenv/lib/python2.6/site-packages/django/db/models/fields/subclassing.py", line 53, in inner return func(*args, **kwargs) File "/home/googledroid/Workspace/eclipse/gameproject/virtualenv/lib/python2.6/site-packages/django/db/models/fields/subclassing.py", line 53, in inner return func(*args, **kwargs) TypeError: get_db_prep_value() got multiple values for keyword argument 'connection' </code></pre> <p>While this works just fine:</p> <pre><code>from django.db.models import CharField as _CharField class CharField(_CharField): def get_db_prep_value(self, value, *args, **kwargs): if self.blank == self.null == self.unique == True and value == '': value = None return super(CharField, self).get_db_prep_value(value, *args, **kwargs) </code></pre> <p>In django source, <code>django.db.models.subclassing.call_with_connection_and_prepared.inner()</code>,I see there is some deletion of kwargs, but not entirely sure why?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload