-
-
Notifications
You must be signed in to change notification settings - Fork 49
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
QueryBuilder created with new_from_builder()
use the same references as the builder it is created from
#682
Comments
Can you simplify this issue? Not really understanding the problem and i feel you left out a lot of code here. You said you are using new_from_builder but i don't see that in your code snippets here |
Maybe a step by step way i can replicate the issue will help |
Sure, sorry for the mess. Let's begin with explaining what we want to do with this code: website_query = Website.with_trashed()
# apply filter
website_query = apply_filter(website_query, filter)
# total items
new_query = website_query.new_from_builder()
total_items = new_query.count()
# pagination
if limit and offset is not None:
website_query = website_query.limit(limit).offset(offset)
# query execution
websites = website_query.get()
Addition to step no.2 is that we do this in website_query._wheres += (
(QueryExpression(None, operator, SubGroupExpression(builder), keyword=kw)),
) We do it to add a sub-query to our query and this is important because What we think is causing the problemProblem is that orm/src/masoniteorm/query/QueryBuilder.py Lines 1967 to 1979 in 3e6fd79
This is causing us issues because when Example 1example showing that QueryBuilder objects have different id(because new one is copy from the old one), but their Example 2Here you can also see how it affects our raw query. Possible solutionI think that the solution would be to make I hope I now added more details, but if anything else stayed unclear, I am willing to explain :) |
@JRubics i'm not sure i was able to replicate this issue (I'm still kind of unclear what i'm looking for 😞) but i took your proposed solution and added it in #716 Can you install that pull request code and test and see if that fixes the issue?
|
Just added deep copy to these tuples https://github.com/MasoniteFramework/orm/pull/716/files |
@josephmancuso sorry, I didn't have time to test it, but I think we already tried this and it didn't solved our issue. We'll test it next week and if it doesn't work, we will try to create small project with this issue and share the code base with you. Thank you for the effort 🙏 |
Hi,
we are trying to do something like this:
where
apply_filter()
besides some wheres, also adds a subquery to the builder:The error that we have is that after doing
count()
(even though we usenew_from_builder
) the query goes from this:to this:
We think the problem is that
new_from_builder()
is creating a new query builder, but adding the data from the old one with reference, so whencount
executesget()
(and get resets the query builder in the end), it also resets the _wheres part of the old query builder. We think it should somehow do a deep copy, but whatever we tried, we didn't manage to solve it.Desktop:
What database are you using?
The text was updated successfully, but these errors were encountered: