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

Implement retry for ServerVersion.AutoDetect in AddMySqlDbContext for Pomelo #2386

Merged
merged 11 commits into from
Feb 28, 2024

Conversation

bgrainger
Copy link
Contributor

@bgrainger bgrainger commented Feb 23, 2024

Fixes #1866.

Microsoft Reviewers: Open in CodeFlow

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-integrations Issues pertaining to Aspire Integrations packages label Feb 23, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Feb 23, 2024
{
try
{
serverVersion = ServerVersion.AutoDetect(connectionString);
Copy link
Member

Choose a reason for hiding this comment

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

Are we sure we want to "double down" on AutoDetect? @lauxjpn indicated it shouldn't be used in production:

#1161 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know that was the recommendation, but from a GitHub code search it looked like most users (unsurprisingly, really) were taking "the easy way out" and using AutoDetect. (I.e., I saw AutoDetect much more in those code search results than a hardcoded version).

I'm at a little bit of a loss to really know what the "right" approach is:

  1. Stop using AutoDetect in Aspire at all: users will have to specify the server version or it will fail at startup.
  2. Strongly encourage specification of a ServerVersion in documentation and examples (e.g., sample app uses builder.AddMySqlDbContext<MyDbContext>("Catalog", settings => settings.ServerVersion = "8.3.0");) but keep this current fallback code in case it's omitted.
  3. Even more strongly encourage its use by making ServerVersion a parameter to .AddMySqlDbContext().

I guess this all boils down to: keep the fallback or not. If there is no fallback, users must supply ServerVersion and we can debate the ergonomics of how best to accomplish that. Even if we keep the fallback, we could still discuss what affordances should be provided to make it as easy as possible to fall into the pit of success. (Adding a parameter to AddMySqlDbContext probably isn't right, as it makes it much more difficult to use per-environment configuration.)

My gut feeling right now is that even though using AutoDetect is strongly discouraged by Pomelo, it is provided and supported, and most consumers seem to use it. So for reasons of inertia, Aspire should do the same thing and we can discuss how to encourage people not to, or at least provide good examples in the documentation. Thoughts?

The code was not using any of the additional features of Microsoft.Extensions.Resilience.
@mitchdenny
Copy link
Member

@eerhardt I've triaged this into P4 but could you decide whether it needs to go in after snap?

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. Thanks for the contribution!

@eerhardt eerhardt merged commit 948351d into dotnet:main Feb 28, 2024
8 checks passed
@bgrainger bgrainger deleted the fix-serverversion branch February 28, 2024 18:25
@lauxjpn
Copy link

lauxjpn commented Feb 29, 2024

Be aware that if you use ServerVersion.AutoDetect, then generate migrations on your development machine, and your local and production MySQL database servers differ even slightly in their version (just one patch level can be enough), then your generated migrations might not work on your production server.

Also, generating migrations without a locally available database server does fail by default when using ServerVersion.AutoDetect.

@github-actions github-actions bot locked and limited conversation to collaborators Apr 21, 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 community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve ServerVersion.AutoDetect in AddMySqlDbContext
5 participants