Skip to content

Commit

Permalink
Merge 3a647ec into 5d7a468
Browse files Browse the repository at this point in the history
  • Loading branch information
dantownsend committed Jan 3, 2021
2 parents 5d7a468 + 3a647ec commit eeb850f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions piccolo/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ def __init_subclass__(
references = cls
else:
if "." in references:
# Don't allow relative modules - this may change in
# the future.
if references.startswith("."):
raise ValueError("Relative imports aren't allowed")

module_path, table_class_name = references.rsplit(
".", maxsplit=1
)
Expand Down
16 changes: 16 additions & 0 deletions tests/columns/test_foreignkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@ def tearDown(self):
Manager.alter().drop_table().run_sync()


class TestForeignKeyRelativeError(TestCase):
def test_foreign_key_relative_error(self):
"""
Make sure that a references argument which contains a relative module
isn't allowed.
"""
with self.assertRaises(ValueError) as manager:

class Band(Table):
manager = ForeignKey("..example_app.tables.Manager", null=True)

self.assertEqual(
manager.exception.__str__(), "Relative imports aren't allowed"
)


class TestReferences(TestCase):
def test_foreign_key_references(self):
"""
Expand Down

0 comments on commit eeb850f

Please sign in to comment.