-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Convert DatabaseErrorPage to exception filter #24588
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
Conversation
6423058
to
cbe1da3
Compare
WIP, consider adding some tests. |
3b9ab63
to
37e2433
Compare
Can you give a screenshot of what the new error page looks like? |
You'll need an EF reviewer for half of this. |
src/Middleware/Diagnostics.EntityFrameworkCore/src/Views/DatabaseErrorPage.cshtml
Outdated
Show resolved
Hide resolved
...ware/Diagnostics.EntityFrameworkCore/test/FunctionalTests/DatabaseErrorPageMiddlewareTest.cs
Outdated
Show resolved
Hide resolved
src/Middleware/Diagnostics.EntityFrameworkCore/src/Strings.resx
Outdated
Show resolved
Hide resolved
src/Middleware/Diagnostics.EntityFrameworkCore/src/DatabaseExceptionFilter.cs
Outdated
Show resolved
Hide resolved
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this belongs in the M.A.Diagnostics namespace along with IDeveloperPageExceptionFilter. It would save most users a using statement.
🆙📅 |
What's the issue tracking this change? |
src/Identity/ApiAuthorization.IdentityServer/samples/ApiAuthSample/Startup.cs
Outdated
Show resolved
Hide resolved
src/Middleware/Diagnostics.EntityFrameworkCore/src/DatabaseErrorPageExtensions.cs
Outdated
Show resolved
Hide resolved
src/Middleware/Diagnostics.EntityFrameworkCore/src/DatabaseExceptionFilter.cs
Outdated
Show resolved
Hide resolved
src/Middleware/Diagnostics.EntityFrameworkCore/src/DatabaseExceptionFilter.cs
Outdated
Show resolved
Hide resolved
src/Middleware/Diagnostics.EntityFrameworkCore/src/DatabaseExceptionFilter.cs
Outdated
Show resolved
Hide resolved
...iddleware/Diagnostics.EntityFrameworkCore/src/HttpContextDatabaseContextDetailsExtensions.cs
Outdated
Show resolved
Hide resolved
...iddleware/Diagnostics.EntityFrameworkCore/src/HttpContextDatabaseContextDetailsExtensions.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update the PR to point to an issue \ add a description that says why this is necessary? I'm not familiar with this area so I'm not sure why this is required.
private readonly ILogger _logger; | ||
private readonly DatabaseErrorPageOptions _options; | ||
|
||
public DatabaseExceptionFilter(ILogger<DatabaseExceptionFilter> logger, IOptions<DatabaseErrorPageOptions> options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I'm reusing the DatabaseErrorPageOptions type originally used by the middleware. Should we introduce a new type that's exactly the same but has a matching name? Something like DatabaseDeveloperPageExceptionFilterOptions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you think the old type is good enough, maybe it's fine. It's unlikely you'll have both of these enabled and want different behavior for the two.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Can you send an email for the api review?
src/Middleware/Diagnostics.EntityFrameworkCore/src/DatabaseDeveloperPageExceptionFilter.cs
Show resolved
Hide resolved
src/Middleware/Diagnostics.EntityFrameworkCore/src/DatabaseDeveloperPageExceptionFilter.cs
Outdated
Show resolved
Hide resolved
...Diagnostics.EntityFrameworkCore/src/DatabaseDeveloperPageExceptionFilterServiceExtensions.cs
Show resolved
Hide resolved
@bricelam Can you take a look at this? Specifically, the code that finds the DbContext registered in D.I. and the code that uses it for Migrations? (Note that we're not attempting to handle every possible way a DbContext might be used in the project, just the cases where it is registered in the ASP.NET container using one of the normal AddDbContext type calls. This is why the discovery code is simpler than we have for EF tooling in general.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
var snapshotModel = migrationsAssembly.ModelSnapshot?.Model; | ||
if (snapshotModel is IConventionModel conventionModel) | ||
{ | ||
var conventionSet = context.GetService<IConventionSetBuilder>().CreateConventionSet(); | ||
|
||
var typeMappingConvention = conventionSet.ModelFinalizingConventions.OfType<TypeMappingConvention>().FirstOrDefault(); | ||
if (typeMappingConvention != null) | ||
{ | ||
typeMappingConvention.ProcessModelFinalizing(conventionModel.Builder, null); | ||
} | ||
|
||
var relationalModelConvention = conventionSet.ModelFinalizedConventions.OfType<RelationalModelConvention>().FirstOrDefault(); | ||
if (relationalModelConvention != null) | ||
{ | ||
snapshotModel = relationalModelConvention.ProcessModelFinalized(conventionModel); | ||
} | ||
} | ||
|
||
if (snapshotModel is IMutableModel mutableModel) | ||
{ | ||
snapshotModel = mutableModel.FinalizeModel(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AndriySvyryd Is all this still necessary? Is there an easier way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Easier way will be enabled by dotnet/efcore#22031
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically we should also call SnapshotModelProcessor.Process()
to fix old snapshots, but this would bring in all kinds of dependencies
Decoupling this from EF and updating WebHost to add this by default in dev scenarios will be done separately.