File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -200,6 +200,11 @@ def __init_subclass__(
200200 references = cls
201201 else :
202202 if "." in references :
203+ # Don't allow relative modules - this may change in
204+ # the future.
205+ if references .startswith ("." ):
206+ raise ValueError ("Relative imports aren't allowed" )
207+
203208 module_path , table_class_name = references .rsplit (
204209 "." , maxsplit = 1
205210 )
Original file line number Diff line number Diff line change @@ -90,6 +90,22 @@ def tearDown(self):
9090 Manager .alter ().drop_table ().run_sync ()
9191
9292
93+ class TestForeignKeyRelativeError (TestCase ):
94+ def test_foreign_key_relative_error (self ):
95+ """
96+ Make sure that a references argument which contains a relative module
97+ isn't allowed.
98+ """
99+ with self .assertRaises (ValueError ) as manager :
100+
101+ class Band (Table ):
102+ manager = ForeignKey ("..example_app.tables.Manager" , null = True )
103+
104+ self .assertEqual (
105+ manager .exception .__str__ (), "Relative imports aren't allowed"
106+ )
107+
108+
93109class TestReferences (TestCase ):
94110 def test_foreign_key_references (self ):
95111 """
You can’t perform that action at this time.
0 commit comments