efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Disable automatic query client evaluation

Open ajcvickers opened this issue 7 years ago • 33 comments

This is planned for 3.0 anyway--see #12795. However, by disabling now for the next preview, we can start getting feedback on the break to prepare for when the 3.0 query changes are in a state to be shipped.

ajcvickers avatar Mar 06 '19 17:03 ajcvickers

Why was the decision made to not allow us to turn this off with the below? I agree that it should be on by default to prevent poor performance, but now this means I have to extensively test my application to make sure some moron didnt write bad code somewhere. This means we will never upgrade to EF Core 3.0. Too much time involved to test. optionsBuilder .UseSqlServer("") .ConfigureWarnings(w => w.Ignore(RelationalEventId.QueryClientEvaluationWarning));

darl0026 avatar Oct 03 '19 20:10 darl0026

Allowing to turn it off, means EF Core would perform automatic client eval. That is additional code to write and maintain.

smitpatel avatar Oct 03 '19 21:10 smitpatel

There is no way that it is the much code to write and maintain. No way i believe that! Do you not understand the impact, we have 100s of web api endpoints that return data. Unfortunately many are missing tests, so there is no way we can go and test them. I cant possibly be the first person who pushed back and said we need a way to turn this off.

darl0026 avatar Oct 03 '19 21:10 darl0026

@darl0026 - You are the first one to ask a way to turn this off as evident by comments on this issue. We would consider a well-written PR with tests to add a way to client eval for all query operators in EF Core codebase if you would like to contribute.

smitpatel avatar Oct 03 '19 21:10 smitpatel

@smitpatel I may be missing something, but I don't think we would accept such a PR. It would be allowing people to opt-in to high risk of regressions in patches, which is one of main the reasons for making this change in the first place.

ajcvickers avatar Oct 03 '19 21:10 ajcvickers

We literally have 100s of linq queries, how are we supposed to mitigate the regression risk? In 2.2 for any greenfield projects, i explicitly configured this option to throw to prevent writing bad queries... but there is too much old code to test. Even if we didnt have 100s of queries, there is still significant regression risk. Like i said, i like the default on... but we have to be able to turn it off. You have provided ways to go back to old behavior for non-high risk breaking changes, why would you not do it for the high-risk breaking changes?

darl0026 avatar Oct 03 '19 21:10 darl0026

@darl0026 on more point in addition to the above: we really do believe that client evaluation is dangerous - both because of potentially critical issues discovered only in production, and because of behavior changes as evaluation switches from client to server between versions. As such, providing an opt in for this problematic behavior would be doing a disservice to our users who would continue using it. And as @smitpatel wrote, supporting this feature and the users running into the issues it generates would cost us a lot of time and effort which are better focused elsewhere.

roji avatar Oct 04 '19 19:10 roji

I absolutely 100% agree that it needs to be in place, this is why I opted into this behavior in earlier versions any time I could, to prevent performance issues. But you have to acknowledge there is a HUGE risk for regression issues. You say that you are concerned about doing a disservice to your customers, by not giving them a way to opt out then it is a disservice. Can you please give me guidance on how to make sure the 100s of linq queries that I have wont throw an exception. You say that you are worried about time and effort, well so am I. I cant possibly go back and test 100s of endpoints that dont have tests (but should have). I am making a prediction, people are going to upgrade to 3.0 (and not read the breaking changes doc, I PROMISE this happens) and get burned and it will come back to bite you. When i upgraded to asp.net core 3.0 at least there were compile time changes that prevented me from going forward and forcing me to think. This is strictly a run-time thing and will never get caught until an exception occurs. I understand that a major version release indicates that there will most likely be breaking changes and you need to test, but this is a big one, it requires full regression testing and I dont have time for it.

darl0026 avatar Oct 04 '19 20:10 darl0026

@jjxtra - Please stop spamming unrelated issues with your group by query is not working.

smitpatel avatar Oct 13 '19 19:10 smitpatel

@darl0026 Not to sound blunt but then, don't upgrade to 3.0 if you're not ready / don't have the time to do so. Its a major version upgrade so breaking changes are to be expected. We're still on 2.2 for this exact reason and I don't think we will be upgrading for a while yet.

Also consider automatic integration testing / end to end testing, that way, if this happens again, you don't have to spend lot of man hours testing for breaking changes, you'll already have a compiled list of all the functionality that is broken and that you need to fix.

To be honest, Id rather it happen now in 3.0 rather than in 9.0 and the code base is bigger, its just something you'll have to deal with, or use something that gives you more control over your queries i.e Dapper.

I advocate for the usage of CQRS to split out the database queries to use Dapper where I get fine control on the query, and EF Core on the commands which gives me benefits such as the change tracker and unit of work pattern.

KieranDevvs avatar Nov 18 '19 14:11 KieranDevvs

As a dev manager with over 40 developers working for me, I have to agree with @darl0026 This is a MAJOR breaking change that could prevent our company from ever upgrading to core 3.0+ And now MSFT have designated that 2.2 is out of life and we have to upgrade to 3.1, but we cant due to EF upgrade! This is kind of insane guys.

At the very least can you provide a tool that could search our codebase in VS.NET as an addin or something to help us find the breaking code up front and re-write.

Or if you cant do that, how about providing some code sample to allow us to turn on logging in production so we log the call stack of failing methods so at least we can build up a picture of our code that needs changing up front? We could dump that into a table or azure table storage and then try to collate all the code that needs fixing up front.

Otherwise what you are telling us to do is to set 2.2 to throw exceptions not warnings, run some code, let a method fail, fix it, compile it, run it, go to next method to test? That could literally take weeks/months in a large code base, and unless all code is covered by automated tests (not unit tests due to mocking of course, as that wont help here). I estimate the cost to my company to do that would be between £20,000-£100,000 which means an impossibility for us financially.

So you guys REALLY have to do something to help us out. If we had known about the client side execution when we started on EF 2, of course we would have turned it on. But it is way too late for that now.

dougiejay avatar Dec 24 '19 11:12 dougiejay

@dougiejay assume you mean "turned it off" ? And how did you miss it in the first place? We're you coming from EF6?

ErikEJ avatar Dec 24 '19 12:12 ErikEJ

@ErikEJ Not sure what you mean. We left EF 2 running in its default settings, we didnt make any changes, it ran out of the box in that mode of allowing client side evaluation from my understanding.

"How did we miss it in the first place?" - As in how did we let something run in it's default mode? Not sure I follow. Surely you put the more dangerous setting (client eval) as the non-default setting that requires a customer to actively opt-in to the situation, not the other way around?

And really, voting down a comment from a corporate client of Microsoft seems pretty petty and shows a disdain for users of the product that you promote and work on.

dougiejay avatar Dec 24 '19 13:12 dougiejay

@dougiejay EF Core versions prior to 3.0 emitted warnings to the log whenever client evaluation occurred; you could tell EF to throw instead - see the documentation section on client evaluation in previous versions. To configure logging, see this page.

However, note that in EF Core 3.0 the query pipeline was also rewritten, so what involved client evaluation in 2.2 may not necessarily throw an exception in 3.0. The best way forward here would be to have a test/preproduction environment running on EF Core 3.1 and to use that to identify problematic queries. Hopefully you also have a test infrastructure to make this process easier.

roji avatar Dec 24 '19 17:12 roji

Again you guys are missing the point. Everyone is happy you have stopped client side evaluation. It was something that we would have avoided if we knew about this feature in 2.0 a year and a half ago (instead of being simply logged to VS. Net console). My point is that you have not provided any upgrade path or tools to assist migration. Yes we have over 600 automated api tests which will help with the migration process, however one api might have multiple db calls, and maybe several will fail due to the client eval, meaning to get one api call passing might take several builds taking significant time. When professional development is conducted by corporate clients like us, we expect a bit more than a serious breaking change and no assistance whatsoever from Microsoft to minimise cost of upgrading. If you don't understand my viewpoint then not much more to say and I will cease posting on this thread.

dougiejay avatar Dec 26 '19 10:12 dougiejay

I absolutely 100% agree that it needs to be in place, this is why I opted into this behavior in earlier versions any time I could, to prevent performance issues. But you have to acknowledge there is a HUGE risk for regression issues. You say that you are concerned about doing a disservice to your customers, by not giving them a way to opt out then it is a disservice. Can you please give me guidance on how to make sure the 100s of linq queries that I have wont throw an exception. You say that you are worried about time and effort, well so am I. I cant possibly go back and test 100s of endpoints that dont have tests (but should have). I am making a prediction, people are going to upgrade to 3.0 (and not read the breaking changes doc, I PROMISE this happens) and get burned and it will come back to bite you. When i upgraded to asp.net core 3.0 at least there were compile time changes that prevented me from going forward and forcing me to think. This is strictly a run-time thing and will never get caught until an exception occurs. I understand that a major version release indicates that there will most likely be breaking changes and you need to test, but this is a big one, it requires full regression testing and I dont have time for it.

Spot on agree with @darl0026

dougiejay avatar Dec 26 '19 10:12 dougiejay

Again you guys are missing the point. [,,,] My point is that you have not provided any upgrade path or tools to assist migration.

I do understand your point, and also the frustration with the situation. This is just my opinion/view, but had it been feasible/possible to provide some sort of automated tool to assist migration, we'd definitely have done it (for example, an analyzer to flag queries which would fail). However, doing this kind of analysis at compile time is an enormous investment (it really is), and time was already very tight to the 3.0 release (which there was no option to postpone). At the end of the day, we could have either made the change without a migration tool, or not have made the change at all - that's just the reality we had to face when making that decision.

And really, voting down a comment from a corporate client of Microsoft seems pretty petty and shows a disdain for users of the product that you promote and work on.

FWIW the only downvote I'm seeing is from @ErikEJ who isn't a Microsoft employee (although he's an important member of the community). I don't think anyone in the EF team takes the client evaluation change lightly, or imagines that the transition would be trivial for customers; it's just that everyone agrees that dropping client evaluation was the right thing to do, and there was no feasible way to provide automated upgrade analysis etc.

roji avatar Dec 27 '19 11:12 roji

@darl0026 I'm very sorry to hear you are having trouble updating to EF Core 3.1. We certainly didn't take the decision lightly to overhaul the query code in the way we did for 3.0. However, after much discussion, we decided it was necessary for several reasons, some of them around robustness and user experience going forward, some of them internal relating to dependencies.

With a change of this size it was clear regressions in existing functionality would occur, even outside the intended breaking changes. We have a small team (five engineers and a manager) so mitigations for this needed to be realistic. We focused on:

  • Getting all the 50,000+ tests in this repo working against the new code
  • Clear documentation of breaking changes
  • Weekly status updates indicating progress
  • Many previews and daily build releases for people to test with and provide feedback

It was not realistic for us to create any kind of static analysis tools for this--we simply don't have the resources for that. It's also not clear to me how many cases could be reasonably picked up by static analysis alone.

In addition, the problem space for LINQ queries is extremely large, which means that it is very easy for patterns to be missed even with tests we run. This means, realistically, using a new release of EF Core (whether it is a breaking release or not) requires that the application test with that new release to identify any issues. This is part of the reason for making frequent preview releases and daily builds available--we hope to encourage and foster relationships with customers so as to tighten the feedback on finding and fixing issues.

This was an extreme case of a breaking release--we don't plan to make this kind of break routinely. However, we are committed to moving the product and experience forward in ways that may be breaking. We are certainly open if you have ideas for how we can further improve in these areas, within the constraints of the resources we have.

ajcvickers avatar Jan 02 '20 22:01 ajcvickers

Thanks for the heads up @ajcvickers, appreciate you being transparent.

jjxtra avatar Jan 02 '20 22:01 jjxtra

  1. Breaking changes are bad when their resolution cannot be quantified.

As a developer, I understand that it's sometimes necessary to make breaking changes, and the LINQ execution change is one I heartily endorse for its potential for improved performance. As someone who has to communicate with stakeholders, I shudder at the thought of trying to sell an EF Core 3.0 upgrade to them. "First we have to end-to-end test the entire application to determine what breaks in EF Core 3.0, then we need to spend an unknown amount of time fixing and testing the broken stuff." How many stakeholders are going to give the go-ahead for that, especially when the upside is "better performance... maybe"?

IMO, the execution engine rewrite is a large enough change that it warranted a special release plan. Personally, I would have released EF Core 2.2.1 that had no change apart from upgrading the client-side execution warning to an error, which would have given developers adequate notice that their current code was problematic and should be changed. Then I would have released EF Core 3.0 with the new engine, and nobody would've had a reason to complain.

  1. Breaking changes are bad when they aren't adequately communicated.

I believe that the big issue that @darl0026 and others, including myself, have is that the breaking nature of EF Core 3 vs older versions WRT query evaluation was not sufficiently communicated. The fact of the matter is that for any EF-using app of decent size, upgrading to EF Core 3 is probably going to cause breakage somewhere due to the new evaluation model, and that isn't called out particularly well.

The announcement for EF Core 3.0 is peppered with weasel words like "can" and "may" and "could", when realistically any reasonably-sized app is going to be affected by these changes. What was, and arguably still is, needed on that blog post is a preface consisting of a big block of text on a red background saying something like:

"Breaking changes: Because EF Core 3.0's internal expression compilation engine has been completely rewritten, existing queries may require modification to work with this version. We strongly recommend that you thoroughly test your application with EF Core 3.0 in order to identify affected queries, and use that as a guideline to determine if updating to this new version at this time is optimal for your software. Read on for details of the changes and potential modifications."

Yes, that blog post did mention and link to the breaking changes, but its emphasis on the "breaking" part was not there, nor was it front and foremost as it should have been.

I can understand why Microsoft and the EF team would be reluctant to potentially scare people away from their software, but the fact of the matter is that EF Core 3.0 is not just a drop-in upgrade, and any issues it potentially causes might only come to light days or months or years later. That's a massive business risk, and Microsoft needs to be responsible and disclose that up-front.

Finally, the fact that there are so many questions on Stack Overflow regarding this exact topic (https://stackoverflow.com/q/59677609/70345 being only the most recent) is a strong indication that the existing language around migrating to EF Core 3.0 is not strong or clear enough.

IanKemp avatar Jan 10 '20 10:01 IanKemp