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

Detect conflicting settings when using EnrichEF #3159

Merged
merged 7 commits into from
Mar 27, 2024
Merged

Conversation

sebastienros
Copy link
Member

@sebastienros sebastienros commented Mar 25, 2024

Fixes #2524

Microsoft Reviewers: Open in CodeFlow

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-integrations Issues pertaining to Aspire Integrations packages label Mar 25, 2024
# Conflicts:
#	src/Components/Aspire.Npgsql.EntityFrameworkCore.PostgreSQL/AspireEFPostgreSqlExtensions.cs
@sebastienros sebastienros requested a review from eerhardt March 26, 2024 00:01
@davidfowl davidfowl changed the title Detect conflgicting settings when using EnrichEF Detect conflicting settings when using EnrichEF Mar 26, 2024
@sebastienros
Copy link
Member Author

Just for Npgsql for now to validate the fix. I think the way the execution strategy is checked is too brittle (passing a null! DbContext).

@AndriySvyryd @roji


if (settings.Retry)
{
var executionStrategy = extension?.ExecutionStrategyFactory?.Invoke(new ExecutionStrategyDependencies(null!, optionsBuilder.Options, null!));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sebastienros just to confirm, you're referring to this right?

/cc @AndriySvyryd

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, new ExecutionStrategyDependencies(null! I don't know any other way to get the actual ExtensionStrategy, and our tests are actually passing a concrete DbContext because we own the type and know how to construct it. There this code makes me sad, the ctor in other EF providers could definitely guard against it, right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there's no other way for 8. But, I assume all of this will be removed for the next version, right? You'd just need to make sure that the user calls Enrich before AddDbContext, so all Aspire configuration can be silently overridden.

For SqlServer you can get this behavior in 8 by calling UseAzureSqlDefaults instead of EnableRetryOnFailure

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'd just need to make sure that the user calls Enrich before AddDbContext

I don't think that's the API experience we are looking for. IMO, the current experience makes more sense:

  1. AddDbContext
  2. EnrichDbContext

If you flip it the other way around, it doesn't really make sense. How can you "Enrich" something before you add it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, perhaps the question is whether Enrich just provides a recommended default configuration or whether it should be authorative over anything specified in AddDbContext.

Personally, I don't see why it should override or throw for any conflicting configuration. A suppressible warning seems more appropriate.

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. As long as @roji and @AndriySvyryd approve.

@sebastienros sebastienros merged commit efcab05 into main Mar 27, 2024
8 checks passed
@sebastienros sebastienros deleted the sebros/configerrors branch March 27, 2024 04:42
@sebastienros
Copy link
Member Author

/backport to release/8.0-preview5

Copy link
Contributor

Started backporting to release/8.0-preview5: https://github.com/dotnet/aspire/actions/runs/8446763097

Copy link
Contributor

@sebastienros backporting to release/8.0-preview5 failed, the patch most likely resulted in conflicts:

$ git am --3way --ignore-whitespace --keep-non-patch changes.patch

Applying: Detect conflgicting settings when using EnrichEF
Using index info to reconstruct a base tree...
M	src/Components/Aspire.Npgsql.EntityFrameworkCore.PostgreSQL/AspireEFPostgreSqlExtensions.cs
Falling back to patching base and 3-way merge...
Auto-merging src/Components/Aspire.Npgsql.EntityFrameworkCore.PostgreSQL/AspireEFPostgreSqlExtensions.cs
CONFLICT (content): Merge conflict in src/Components/Aspire.Npgsql.EntityFrameworkCore.PostgreSQL/AspireEFPostgreSqlExtensions.cs
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
Patch failed at 0001 Detect conflgicting settings when using EnrichEF
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

Copy link
Contributor

@sebastienros an error occurred while backporting to release/8.0-preview5, please check the run log for details!

Error: git am failed, most likely due to a merge conflict.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-integrations Issues pertaining to Aspire Integrations packages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enrich EF APIs overwrite an existing ExecutionStrategy by default
5 participants