kayak / pypika

PyPika is a python SQL query builder that exposes the full richness of the SQL language using a syntax that reflects the resulting query. PyPika excels at all sorts of SQL queries but is especially useful for data analysis.
http://pypika.readthedocs.io/en/latest/
Apache License 2.0
2.5k stars 295 forks source link

Union performed on two other _SetOperation type queries throws error when get_sql() is called. #716

Open tripti-nference opened 1 year ago

tripti-nference commented 1 year ago

https://github.com/kayak/pypika/blob/30574f997c80851f7e940ad09a63e14a98871dd3/pypika/queries.py#L606-L611 Here, set_operation operator is UNION and _set_operation_query itself could be a _SetOperation type instead of QueryBuilder which gives error when len() is applied on set_operation_query._selects. Hence, the above codelines should be fixed so that it doesn't give below error when UNION is performed on 2 _SetOperation queries.

    if len(self.base_query._selects) != len(set_operation_query._selects):
TypeError: object of type 'Field' has no len()

Please refer below screenshot for steps to reproduce the issue.

Screenshot 2023-01-23 at 12 00 50 PM

Note : Typecheck on input parameter set_operation is needed here.