raise NotImplementedError()
def get_params(self, **params):
- """Deprecated. use construct_params(). (supports unicode names)
+ """Use construct_params(). (supports unicode names)
"""
return self.construct_params(params)
+ get_params = util.deprecated(get_params)
def construct_params(self, params):
"""Return the bind params for this compiled object.
self.lazy = lazy
self.foreign_keys = util.to_set(foreign_keys)
self._legacy_foreignkey = util.to_set(foreignkey)
+ if foreignkey:
+ util.warn_deprecated('foreignkey option is deprecated; see docs for details')
self.collection_class = collection_class
self.passive_deletes = passive_deletes
self.remote_side = util.to_set(remote_side)
self.cascade = mapperutil.CascadeOptions(cascade)
else:
if private:
+ util.warn_deprecated('private option is deprecated; see docs for details')
self.cascade = mapperutil.CascadeOptions("all, delete-orphan")
else:
self.cascade = mapperutil.CascadeOptions("save-update, merge")
self.association = association
+ if association:
+ util.warn_deprecated('association option is deprecated; see docs for details')
self.order_by = order_by
self.attributeext=attributeext
if isinstance(backref, str):
raise exceptions.ArgumentError("In relationship '%s', primary and secondary join conditions must not include columns from the polymorphic 'select_table' argument as of SA release 0.3.4. Construct join conditions using the base tables of the related mappers." % (str(self)))
def _determine_fks(self):
- if len(self._legacy_foreignkey) and not self._is_self_referential():
+ if self._legacy_foreignkey and not self._is_self_referential():
self.foreign_keys = self._legacy_foreignkey
def col_is_part_of_mappings(col):
# for a self referential mapper, if the "foreignkey" is a single or composite primary key,
# then we are "many to one", since the remote site of the relationship identifies a singular entity.
# otherwise we are "one to many".
- if len(self._legacy_foreignkey):
+ if self._legacy_foreignkey:
for f in self._legacy_foreignkey:
if not f.primary_key:
self.direction = sync.ONETOMANY
return self._legacy_filter_by(*args, **params).one()
-
+ for deprecated_method in ['list', 'scalar', 'count_by',
+ 'select_whereclause', 'get_by', 'select_by', 'join_by', 'selectfirst',
+ 'selectone', 'select', 'execute', 'select_statement', 'select_text',
+ 'join_to', 'join_via', 'selectfirst_by', 'selectone_by']:
+ exec('%s = util.deprecated(%s, False)' % (deprecated_method, deprecated_method))
Query.logger = logging.class_logger(Query)
"within this ``Session`` keyed to their `_instance_key` value.")
def import_instance(self, *args, **kwargs):
- """Deprecated. A synynom for ``merge()``."""
+ """A synynom for ``merge()``."""
return self.merge(*args, **kwargs)
+ import_instance = util.deprecated(import_instance)
# this is the AttributeManager instance used to provide attribute behavior on objects.
# to all the "global variable police" out there: its a stateless object.
"""return True if this MetaData is bound to an Engine."""
return self._bind is not None
+ def _connect(self, bind, **kwargs):
+ from sqlalchemy.engine.url import URL
+ if isinstance(bind, (basestring, URL)):
+ self._bind = sqlalchemy.create_engine(bind, **kwargs)
+ else:
+ self._bind = bind
+
def connect(self, bind, **kwargs):
"""bind this MetaData to an Engine.
directly to the given Engine.
"""
-
- from sqlalchemy.engine.url import URL
- if isinstance(bind, (basestring, URL)):
- self._bind = sqlalchemy.create_engine(bind, **kwargs)
- else:
- self._bind = bind
+ self._connect(bind, **kwargs)
+ connect = util.deprecated(connect, False)
- bind = property(lambda self:self._bind, connect, doc="""an Engine or Connection to which this MetaData is bound. this is a settable property as well.""")
+ bind = property(lambda self:self._bind, _connect, doc="""an Engine or Connection to which this MetaData is bound. this is a settable property as well.""")
def clear(self):
self.tables.clear()
"""
scalar = kwargs.pop('scalar', False)
+ if scalar:
+ util.warn_deprecated('scalar option is deprecated; see docs for details')
s = Select(columns, whereclause=whereclause, from_obj=from_obj, **kwargs)
if scalar:
return s.as_scalar()
def _get_key(self):
return self.scopefunc()
+
+
+_warned = Set()
+
+def warn_deprecated(msg):
+ if msg in _warned:
+ return
+ _warned.add(msg)
+ warnings.warn(msg, category=DeprecationWarning, stacklevel=3)
+
+def deprecated(func, add_deprecation_to_docstring=True):
+ def func_with_warning(*args, **kwargs):
+ if func in _warned:
+ return func(*args, **kwargs)
+ _warned.add(func)
+ warnings.warn("Call to deprecated function %s" % func.__name__,
+ category=DeprecationWarning,
+ stacklevel=2)
+ return func(*args, **kwargs)
+ func_with_warning.__name__ = func.__name__
+ func_with_warning.__doc__ = (add_deprecation_to_docstring and 'Deprecated.\n' or '') + func.__doc__
+ func_with_warning.__dict__.update(func.__dict__)
+ return func_with_warning