]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
add warnings for deprecated methods and options
authorJonathan Ellis <jbellis@gmail.com>
Mon, 30 Jul 2007 23:38:27 +0000 (23:38 +0000)
committerJonathan Ellis <jbellis@gmail.com>
Mon, 30 Jul 2007 23:38:27 +0000 (23:38 +0000)
lib/sqlalchemy/engine/base.py
lib/sqlalchemy/orm/properties.py
lib/sqlalchemy/orm/query.py
lib/sqlalchemy/orm/session.py
lib/sqlalchemy/schema.py
lib/sqlalchemy/sql.py
lib/sqlalchemy/util.py

index deeb7ec4e4ea6328d8e64d59405772c63dcc4bcc..5e6c74c919f260a7e9fb2c48b23980fe77502cac 100644 (file)
@@ -452,10 +452,11 @@ class Compiled(object):
         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.
index a6bb1a371d67db0d8adbe176229534193713952e..600dab41f097cdaa801e8b2ecb469c03220197c3 100644 (file)
@@ -137,6 +137,8 @@ class PropertyLoader(StrategizedProperty):
         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)
@@ -150,11 +152,14 @@ class PropertyLoader(StrategizedProperty):
             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):
@@ -399,7 +404,7 @@ class PropertyLoader(StrategizedProperty):
                 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):
@@ -467,7 +472,7 @@ class PropertyLoader(StrategizedProperty):
             # 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
index 01562f7b510b7e51f5fc8bbc82019f3433ef32f5..1e091c5e64555098368ae37baaa5fc8cae97a0da 100644 (file)
@@ -1147,7 +1147,11 @@ class Query(object):
 
         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)
 
index 87604dde4cf3df24f610e7e6258e1a805335a4f3..d336c57277159432be872beaae1de7c8bc75fc71 100644 (file)
@@ -733,9 +733,10 @@ class Session(object):
                             "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.
index 21822e3a4699642013515fc44c33b81ef5b9e177..17d4d1c771415594ddf6319051828699071b2e3b 100644 (file)
@@ -1125,6 +1125,13 @@ class MetaData(SchemaItem):
         """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.
             
@@ -1137,14 +1144,10 @@ class MetaData(SchemaItem):
                 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()
index e09dcca8dcdd487d09f88ed2b50fe47638c0501b..b27e8237033edc86b7b650c34139f2c1aa3a3282 100644 (file)
@@ -215,6 +215,8 @@ def select(columns=None, whereclause=None, from_obj=[], **kwargs):
       
     """
     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()
index e711de3a3e93e16debf4c00ea72ef97068c0d7e2..c9c20ef451571b48a89eb984995bbe620f07d102 100644 (file)
@@ -539,3 +539,26 @@ class ScopedRegistry(object):
 
     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