Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sub Selects binding error for multiple where clauses #494

Closed
circulon opened this issue Aug 13, 2021 · 1 comment
Closed

Sub Selects binding error for multiple where clauses #494

circulon opened this issue Aug 13, 2021 · 1 comment
Labels
bug An existing feature is not working as intended

Comments

@circulon
Copy link
Contributor

circulon commented Aug 13, 2021

Describe the bug
Using a sub select that has more than 1 filter in the where clause throws a binding error (too many arguments) when using .get().

Strangely the to_sql() does not throw this error (when using the same query) and returns a properly built query that is testable in db clients

To Reproduce

test_table = SomeModel.get_table_name()
date_today = date_utc.add(days=1).to_date_string()
date_7_days_ago = date_utc.subtract(days=6).to_date_string()
stats_builder = (
            QueryBuilder()
            .from_(test_table)
            .where("user_id", current_user.id)
            .count("id as all_time_count")
            .avg("rating as all_timerating_avg")
            .max("rating as all_time_rating_max")
            .add_select(
                "count_days_7",
                lambda query: (
                    query.count("id as lc".format(test_table))
                    .from_(test_table)
                    .where("user_id", current_user.id)
                    # adding 1 or more of the following results in a binding error
                    # Yes I know they are the same but this is just an example ;)
                    .between('updated_at', date_7_days_ago, date_today)  
                    .where("updated_at", ">=", date_7_days_ago)
                    .where("updated_at", "<=", date_today)
                   
                   # Where_raw DOES NOT throw the binding error presumably because 
                   # the values are inserted into the string and not being quoted as per bindings are 
                   .where_raw(
                        "updated_at BETWEEN '{}' AND '{}'".format(
                            date_7_days_ago, date_today
                        )
                    )
                ),
            )

# this works
logging.info(stats_builder.to_sql())
# this throws a binding error        
stats_result = stats_builder.get()[0]

Expected behavior
Sub selects with multiple where filters should work as expected

Desktop (please complete the following information):

  • OS: Mac OSX
  • Version 10.15.7

What database are you using?

  • Type: Postgres
  • Version 10.7
  • Masonite ORM v1.0.55
@circulon circulon added the bug An existing feature is not working as intended label Aug 13, 2021
@circulon circulon changed the title Sub Selects bing error for multiple where clauses Sub Selects binding error for multiple where clauses Aug 13, 2021
@josephmancuso
Copy link
Member

Fixed in #542

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An existing feature is not working as intended
Projects
Development

No branches or pull requests

2 participants