-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
EF Core 1.1.1 has introduced a new ArgumentException for complex queries with with subqueries, if the same subquery is present multiple times in the query model #7944
Comments
@maumar - Did you investigate this? |
In |
While having defensive add to dictionary is safe to do, we should also investigate the reason for it to arise and evaluate if we want to preserve the first value or last value. Also if such cases should be impossible (but happening due to bug somewhere else) then defensive check would make it harder for us to catch the issue. |
@shaulbehr are there other operations applied on the IQueryable in the |
standalone repro: class Program
{
static void Main(string[] args)
{
using (var ctx = new MyContext())
{
ctx.Database.EnsureCreated();
var innerQuery = from c in ctx.Customers
let customers = ctx.Customers.Select(cc => cc)
where customers.Any()
select customers;
var outerQuery = ctx.Customers.Where(c => innerQuery.Any()).ToList();
}
}
}
public class MyContext : DbContext
{
public DbSet<Customer> Customers { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(@"Server=.;Database=Repro7944;Trusted_Connection=True;MultipleActiveResultSets=true");
}
}
public class Customer
{
public int Id { get; set; }
} |
…or complex queries with with subqueries, if the same subquery is present multiple times in the query model Problem was that when we fixed #7476 we introduced a mechanism to copy and then restore query models to prevent them from being corrupted during (failed) attempt at translating them to SQL. However we have not accounted for the case where the same subquery would be present in the query model more than once (same reference). Fix is to add defensive check to the logic that creates a copy of a query model. If we already copied that particular (sub)query model, we don't need to do it twice. It is safe to do, because all occurrences of the query model that share the same reference are guaranteed to have the same body clauses and therefore can later be re-created from the same copy.
…or complex queries with with subqueries, if the same subquery is present multiple times in the query model Problem was that when we fixed #7476 we introduced a mechanism to copy and then restore query models to prevent them from being corrupted during (failed) attempt at translating them to SQL. However we have not accounted for the case where the same subquery would be present in the query model more than once (same reference). Fix is to add defensive check to the logic that creates a copy of a query model. If we already copied that particular (sub)query model, we don't need to do it twice. It is safe to do, because all occurrences of the query model that share the same reference are guaranteed to have the same body clauses and therefore can later be re-created from the same copy.
Fixed in 0594995 |
Justification to include this in 1.1.2 release: Impact: Medium. This is a regression introduced by patch 1.1.1 and was reported by a customer. However the scenario affected is quite complex - it requires a subquery nested within another subquery. Risk: Low. Fix is very local - basically we are adding defensive check when trying to add an item to a dictionary. They only scenarios that could possibly be affected by the fix are currently broken due to this bug. |
This patch fix is approved. Please follow the normal code review / pull request process and make sure you make the change in the correct branch. |
Preview builds of this patch fix should be available on the following feeds:
If you have a chance, please try out these preview builds and let us know if you have any feedback! |
@shaulbehr Could you please check that this issue is fixed for you using the feed posted above? It would be really great to confirm that the issue is fixed in a real-world scenario and that it doesn't regress functionality in some other way. It would be greatly appreciated. |
@ajcvickers : For our actual production code we decided only to use release code (not previews). But for the sake of this exercise I branched off and upgraded to preview 24623 (which was latest available at this time of writing). Regrettably I couldn't get past my integration test setup because of some other changes that appear to be broken by the way I'm declaring my relationships:
Firstly, I know I shouldn't have to declare those relationships in both entities, but I've tried all combinations. And I still get the following error:
Should I log a new bug for this? |
@shaulbehr Thanks for trying it. Yes, please file an issue for the new bug. We will investigate. |
@shaulbehr How are the primary keys defined on those two entity types? |
@AndriySvyryd Can you investigate this as a possible regression from 1.1.1 to 1.1.2? |
@shaulbehr Did you test this with the latest nightly build, or with the 1.1.2 preview feed posted in the comments above? |
@shaulbehr I wasn't able to repro the new issue using the 1.1.2 nightly. Please provide a complete code listing when filing a new issue for this. |
@ajcvickers It was the daily build. I'll try again with the 1.1.2 preview. |
You made a typo, I think.
Should be:
(and public, not publics) |
@ErikEJ I deleted my previous comment - was my bad. |
Confirmed: patch has fixed my problem. Thanks! |
@shaulbehr Thanks for checking! Much appreciated. Can you still file the issue for what you are seeing on dev? |
@ajcvickers Done |
Verified fixed in 1.1.2 candidate build. |
I saw today that EF Core 1.1 has been released. I made a new branch and upgraded from 1.0. Now several of our integration tests are failing with the below error. I'm not going to attempt to give you the full code base that raises this error; our codebase is massive. Rather I will just paste the line of code that throws the error along with the stack trace and hope this will be helpful to you. In the meantime I'm abandoning my attempt to upgrade until I hear back that this bug has been repaired.
The line of code that raises the exception:
where
pagedResult
is anIQueryable<>
that has had a.Skip().Take()
applied to it. I verified that if the skip+take is removed, the exception is not thrown.Stack trace:
The text was updated successfully, but these errors were encountered: