Skip to content

Commit 986b0c6

Browse files
committed
moved some ForeignKeyMeta setup from Table metaclass to ForeignKey constructor
1 parent f53f2db commit 986b0c6

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

piccolo/columns/column_types.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,15 +1037,14 @@ def __init__(
10371037
)
10381038
super().__init__(default=default, null=null, **kwargs)
10391039

1040-
if t.TYPE_CHECKING: # pragma: no cover
1041-
# This is here just for type inference - the actual value is set by
1042-
# the Table metaclass.
1043-
from piccolo.table import Table
1044-
1045-
if not hasattr(self, "_foreign_key_meta"):
1046-
self._foreign_key_meta = ForeignKeyMeta(
1047-
Table, OnDelete.cascade, OnUpdate.cascade
1048-
)
1040+
# This is here just for type inference - the actual value is set by
1041+
# the Table metaclass. We can't set the actual value here, as
1042+
# only the metaclass has access to the table.
1043+
from piccolo.table import Table
1044+
1045+
self._foreign_key_meta = ForeignKeyMeta(
1046+
Table, OnDelete.cascade, OnUpdate.cascade
1047+
)
10491048

10501049
def copy(self) -> ForeignKey:
10511050
column: ForeignKey = copy.copy(self)

piccolo/table.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,7 @@ def __init_subclass__(
210210
)
211211

212212
if is_lazy or is_table_class:
213-
foreign_key_column._foreign_key_meta = ForeignKeyMeta(
214-
references=references,
215-
on_delete=params["on_delete"],
216-
on_update=params["on_update"],
217-
)
213+
foreign_key_column._foreign_key_meta.references = references
218214
else:
219215
raise ValueError(
220216
"Error - ``references`` must be a ``Table`` subclass, or "

0 commit comments

Comments
 (0)