Skip to content

Commit

Permalink
fix Field.__init__ (#742)
Browse files Browse the repository at this point in the history
  • Loading branch information
WH-2099 authored Apr 17, 2024
1 parent f1552da commit 822140e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pypika/terms.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,10 @@ def __init__(
) -> None:
super().__init__(alias=alias)
self.name = name
if isinstance(table, str):
# avoid circular import at load time
from pypika.queries import Table
table = Table(table)
self.table = table

def nodes_(self) -> Iterator[NodeT]:
Expand Down
7 changes: 7 additions & 0 deletions pypika/tests/test_terms.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ def test_when_alias_specified(self):
self.assertEqual('bar', str(c1.alias))


class FieldInitTests(TestCase):
def test_init_with_str_table(self):
test_table_name = "test_table"
field = Field(name="name", table=test_table_name)
self.assertEqual(field.table, Table(name=test_table_name))


class FieldHashingTests(TestCase):
def test_tabled_eq_fields_equally_hashed(self):
client_name1 = Field(name="name", table=Table("clients"))
Expand Down

0 comments on commit 822140e

Please sign in to comment.