Skip to content

Commit

Permalink
Merge 7de28f2 into 8a60f0c
Browse files Browse the repository at this point in the history
  • Loading branch information
YiuRULE committed Jul 9, 2021
2 parents 8a60f0c + 7de28f2 commit d3df83f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 4 additions & 1 deletion pypika/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,10 @@ def where(self, criterion: Union[Term, EmptyCriterion]) -> "QueryBuilder":
self._wheres = criterion

@builder
def having(self, criterion: Term) -> "QueryBuilder":
def having(self, criterion: Union[Term, EmptyCriterion]) -> "QueryBuilder":
if isinstance(criterion, EmptyCriterion):
return

if self._havings:
self._havings &= criterion
else:
Expand Down
7 changes: 6 additions & 1 deletion pypika/tests/test_selects.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,16 @@ def test_where_field_matches_rlike(self):

self.assertEqual('SELECT * FROM "abc" WHERE "foo" RLIKE \'^b\'', str(q))

def test_ignore_empty_criterion(self):
def test_ignore_empty_criterion_where(self):
q1 = Query.from_(self.t).select("*").where(EmptyCriterion())

self.assertEqual('SELECT * FROM "abc"', str(q1))

def test_ignore_empty_criterion_having(self):
q1 = Query.from_(self.t).select("*").having(EmptyCriterion())

self.assertEqual('SELECT * FROM "abc"', str(q1))

def test_select_with_force_index_and_where(self):
q = Query.from_("abc").select("foo").where(self.t.foo == self.t.bar).force_index("egg")

Expand Down

0 comments on commit d3df83f

Please sign in to comment.