]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Using the same ForeignKey object repeatedly
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 3 Dec 2008 14:09:34 +0000 (14:09 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 3 Dec 2008 14:09:34 +0000 (14:09 +0000)
raises an error instead of silently failing
later. [ticket:1238]

CHANGES
lib/sqlalchemy/schema.py
test/sql/constraints.py

diff --git a/CHANGES b/CHANGES
index ca1cf8780383ec5804e3a9a6b48e93b13e8f1025..562a5baa8ff992a3f9c8282535ab5091a60020d6 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -65,6 +65,10 @@ CHANGES
 - sql
     - Fixed the import weirdness in sqlalchemy.sql
       to not export __names__ [ticket:1215].
+    
+    - Using the same ForeignKey object repeatedly
+      raises an error instead of silently failing
+      later. [ticket:1238]
       
     - Added NotImplementedError for params() method
       on Insert/Update/Delete constructs.  These items
index aad1199060cad7b12a040726a7be086612fc31c0..e9e49ba0edfed9836a8cd7f4b66b57b0b7297c89 100644 (file)
@@ -872,6 +872,8 @@ class ForeignKey(SchemaItem):
         return _column
 
     def _set_parent(self, column):
+        if hasattr(self, 'parent'):
+            raise exc.InvalidRequestError("This ForeignKey already has a parent !")
         self.parent = column
 
         if self.parent._pre_existing_column is not None:
index b7208532c5b8ca4179f12f1714fa4189cd39ee3c..ab08c6d981d02f9d8b2c0ba832ca1189a76e0335 100644 (file)
@@ -29,7 +29,16 @@ class ConstraintTest(TestBase, AssertsExecutionResults):
             ForeignKeyConstraint(['emp_id', 'emp_soc'], ['employees.id', 'employees.soc'])
             )
         metadata.create_all()
-
+    
+    def test_double_fk_usage_raises(self):
+        f = ForeignKey('b.id')
+        
+        self.assertRaises(exc.InvalidRequestError, Table, "a", metadata,
+            Column('x', Integer, f),
+            Column('y', Integer, f)
+        )
+        
+        
     def test_circular_constraint(self):
         a = Table("a", metadata,
             Column('id', Integer, primary_key=True),