Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removed deprecated legacy connection handling for `Field.get_db_*`.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@15958 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit e57cc90c164ca9e078882158d830c5d9f717e13b 1 parent 4a6cb38
@alex alex authored
View
2  django/db/models/fields/__init__.py
@@ -7,7 +7,6 @@
from itertools import tee
from django.db import connection
-from django.db.models.fields.subclassing import LegacyConnection
from django.db.models.query_utils import QueryWrapper
from django.conf import settings
from django import forms
@@ -46,7 +45,6 @@ class FieldDoesNotExist(Exception):
class Field(object):
"""Base class for all field types"""
- __metaclass__ = LegacyConnection
# Designates whether empty strings fundamentally are allowed at the
# database level.
View
67 django/db/models/fields/subclassing.py
@@ -6,72 +6,7 @@
to_python() and the other necessary methods and everything will work seamlessly.
"""
-from inspect import getargspec
-from warnings import warn
-
-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
-
-def call_with_connection_and_prepared(func):
- arg_names, varargs, varkwargs, defaults = getargspec(func)
- updated = (
- ('connection' in arg_names or varkwargs) and
- ('prepared' in arg_names or varkwargs)
- )
- if not updated:
- warn("A Field class whose %s method hasn't been updated to take "
- "`connection` and `prepared` arguments." % 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']
- if 'prepared' in kwargs:
- del kwargs['prepared']
- return func(*args, **kwargs)
- return inner
-
-class LegacyConnection(type):
- """
- A metaclass to normalize arguments give to the get_db_prep_* and db_type
- methods on fields.
- """
- def __new__(cls, name, bases, attrs):
- new_cls = super(LegacyConnection, cls).__new__(cls, name, bases, attrs)
- for attr in ('db_type', 'get_db_prep_save'):
- setattr(new_cls, attr, call_with_connection(getattr(new_cls, attr)))
- for attr in ('get_db_prep_lookup', 'get_db_prep_value'):
- setattr(new_cls, attr, call_with_connection_and_prepared(getattr(new_cls, attr)))
- return new_cls
-
-class SubfieldBase(LegacyConnection):
+class SubfieldBase(type):
"""
A metaclass for custom Field subclasses. This ensures the model's attribute
has the descriptor protocol attached to it.
View
4 tests/modeltests/field_subclassing/fields.py
@@ -40,7 +40,7 @@ def to_python(self, value):
return value
return Small(value[0], value[1])
- def get_db_prep_save(self, value):
+ def get_db_prep_save(self, value, connection):
return unicode(value)
def get_prep_lookup(self, lookup_type, value):
@@ -70,7 +70,7 @@ def to_python(self, value):
value = json.loads(value)
return value
- def get_db_prep_save(self, value):
+ def get_db_prep_save(self, value, connection):
if value is None:
return None
return json.dumps(value)
Please sign in to comment.
Something went wrong with that request. Please try again.