Skip to content

Commit

Permalink
fix functions.Function not passing down kwargs during sql generation …
Browse files Browse the repository at this point in the history
…of function
  • Loading branch information
larsschwegmann committed Oct 2, 2024
1 parent 2054a6a commit 614ffda
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions pypika/terms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
import re
import uuid
from datetime import date, time, datetime
from datetime import date, datetime, time
from enum import Enum
from typing import (
TYPE_CHECKING,
Expand Down Expand Up @@ -1429,7 +1429,7 @@ def get_sql(self, **kwargs: Any) -> str:

# FIXME escape
function_sql = self.get_function_sql(
with_namespace=with_namespace, quote_char=quote_char, dialect=dialect
with_namespace=with_namespace, quote_char=quote_char, dialect=dialect, **kwargs
)

if self.schema is not None:
Expand Down
15 changes: 14 additions & 1 deletion tests/test_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
Query,
Tables,
)
from pypika.terms import ListParameter, ParameterValueWrapper
from pypika.functions import Upper
from pypika.terms import ListParameter, ParameterValueWrapper, ValueWrapper


class ParametrizedTests(unittest.TestCase):
Expand Down Expand Up @@ -212,3 +213,15 @@ def test_pyformat_parameter(self):
'INSERT INTO "abc" ("a","b","c") VALUES (%(param1)s,%(param2)s,%(param3)s)', sql
)
self.assertEqual({"param1": 1, "param2": 2.2, "param3": "foo"}, parameter.get_parameters())

def test_function_parameter(self):
q = (
Query.from_(self.table_abc)
.select("*")
.where(self.table_abc.category == Upper(ValueWrapper("foobar")))
)
p = ListParameter("%s")
sql = q.get_sql(parameter=p)
self.assertEqual('SELECT * FROM "abc" WHERE "category"=UPPER(%s)', sql)

self.assertEqual(["foobar"], p.get_parameters())

0 comments on commit 614ffda

Please sign in to comment.