Repository: kayak/pypika
Pull request #433 (2020-05-06 13:25:12)

Undo the showing of aliases of fields that are arguments of a function
This is essentially a rollback of https://github.com/kayak/pypika/pull/392. I commented on that pull request as well.

The linked PR made too drastic changes that had a big impact on existing usages. We should either provide a migration guide or find a different solution for this feature. 

coveralls: 
[![Coverage Status](https://coveralls.io/builds/30598181/badge)](https://coveralls.io/builds/30598181)

Coverage remained the same at ?% when pulling **7f7b2de0508132a5f1de484e371f1a0a16947286 on gl3nn:no-nested-alias** into **3d87ac3c0741c8f0cd3b73e825213190d36c00ae on kayak:master**.


Patch:
diff --git a/pypika/__init__.py b/pypika/__init__.py
index 0992199..c65c44e 100644
--- a/pypika/__init__.py
+++ b/pypika/__init__.py
@@ -94,4 +94,4 @@ from pypika.utils import (
 
 __author__ = "Timothy Heys"
 __email__ = "theys@kayak.com"
-__version__ = "0.37.5"
+__version__ = "0.37.4"
diff --git a/pypika/queries.py b/pypika/queries.py
index 65dfd71..2ab94ed 100644
--- a/pypika/queries.py
+++ b/pypika/queries.py
@@ -772,7 +772,7 @@ class QueryBuilder(Selectable, Term):
         if self._insert_table is None:
             raise AttributeError("'Query' object has no attribute '%s'" % "insert")
 
-        if terms and isinstance(terms[0], (list, tuple)):
+        if isinstance(terms[0], (list, tuple)):
             terms = terms[0]
 
         for term in terms:
diff --git a/pypika/terms.py b/pypika/terms.py
index 147dde9..f16143e 100644
--- a/pypika/terms.py
+++ b/pypika/terms.py
@@ -1156,7 +1156,7 @@ class Function(Criterion):
         return "{name}({args}{special})".format(
               name=self.name,
               args=",".join(
-                    p.get_sql(with_alias=True, **kwargs)
+                    p.get_sql(with_alias=False, **kwargs)
                     if hasattr(p, "get_sql")
                     else str(p)
                     for p in self.args
diff --git a/setup.cfg b/setup.cfg
index 30d5b0a..5a69037 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,5 +1,5 @@
 [bumpversion]
-current_version = 0.37.5
+current_version = 0.37.4
 commit = True
 tag = True
 


Test patch:
diff --git a/pypika/tests/test_inserts.py b/pypika/tests/test_inserts.py
index 3f888c6..7a3ada7 100644
--- a/pypika/tests/test_inserts.py
+++ b/pypika/tests/test_inserts.py
@@ -113,17 +113,6 @@ class InsertIntoTests(unittest.TestCase):
             'INSERT INTO "abc" ("foo","bar","buz") VALUES (1,\'a\',true)', str(query)
         )
 
-    def test_insert_empty_columns(self):
-        query = (
-            Query.into(self.table_abc)
-            .columns()
-            .insert(1, "a", True)
-        )
-
-        self.assertEqual(
-            'INSERT INTO "abc" VALUES (1,\'a\',true)', str(query)
-        )
-
     def test_insert_selected_columns_type_list(self):
         query = (
             Query.into(self.table_abc)
@@ -135,17 +124,6 @@ class InsertIntoTests(unittest.TestCase):
             'INSERT INTO "abc" ("foo","bar","buz") VALUES (1,\'a\',true)', str(query)
         )
 
-    def test_insert_empty_columns_type_list(self):
-        query = (
-            Query.into(self.table_abc)
-            .columns([])
-            .insert(1, "a", True)
-        )
-
-        self.assertEqual(
-            'INSERT INTO "abc" VALUES (1,\'a\',true)', str(query)
-        )
-
     def test_insert_selected_columns_type_tuple(self):
         query = (
             Query.into(self.table_abc)
@@ -157,17 +135,6 @@ class InsertIntoTests(unittest.TestCase):
             'INSERT INTO "abc" ("foo","bar","buz") VALUES (1,\'a\',true)', str(query)
         )
 
-    def test_insert_empty_columns_type_tuple(self):
-        query = (
-            Query.into(self.table_abc)
-            .columns(())
-            .insert(1, "a", True)
-        )
-
-        self.assertEqual(
-            'INSERT INTO "abc" VALUES (1,\'a\',true)', str(query)
-        )
-
     def test_insert_none_skipped(self):
         query = Query.into(self.table_abc).insert()
 
diff --git a/pypika/tests/test_selects.py b/pypika/tests/test_selects.py
index 1f07317..2a4569b 100644
--- a/pypika/tests/test_selects.py
+++ b/pypika/tests/test_selects.py
@@ -862,14 +862,20 @@ class AliasTests(unittest.TestCase):
         self.assertEqual('SELECT COUNT(*) "foo" FROM "abc"', str(q))
 
     def test_function_using_as_nested(self):
+        """
+        We don't show aliases of fields that are arguments of a function.
+        """
         q = Query.from_(self.t).select(fn.Sqrt(fn.Count("*").as_("foo")).as_("bar"))
 
-        self.assertEqual('SELECT SQRT(COUNT(*) "foo") "bar" FROM "abc"', str(q))
+        self.assertEqual('SELECT SQRT(COUNT(*)) "bar" FROM "abc"', str(q))
 
     def test_functions_using_constructor_param_nested(self):
+        """
+        We don't show aliases of fields that are arguments of a function.
+        """
         q = Query.from_(self.t).select(fn.Sqrt(fn.Count("*", alias="foo"), alias="bar"))
 
-        self.assertEqual('SELECT SQRT(COUNT(*) "foo") "bar" FROM "abc"', str(q))
+        self.assertEqual('SELECT SQRT(COUNT(*)) "bar" FROM "abc"', str(q))
 
     def test_ignored_in_where(self):
         q = Query.from_(self.t).select(self.t.foo).where(self.t.foo.as_("bar") == 1)