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

Double database connexion validation in SetupService #12825

Closed
TFleury opened this issue Nov 16, 2022 · 3 comments · Fixed by #12826
Closed

Double database connexion validation in SetupService #12825

TFleury opened this issue Nov 16, 2022 · 3 comments · Fixed by #12826
Assignees
Labels
Milestone

Comments

@TFleury
Copy link
Contributor

TFleury commented Nov 16, 2022

It seems to me that there is a double database connexion validation in SetupService.

There is the IDbConnectionValidator.ValidateAsync method

switch (await _dbConnectionValidator.ValidateAsync(shellSettings["DatabaseProvider"], shellSettings["ConnectionString"], shellSettings["TablePrefix"], shellSettings.Name))
{
case DbConnectionValidatorResult.NoProvider:
context.Errors.Add(String.Empty, S["DatabaseProvider setting is required."]);
break;
case DbConnectionValidatorResult.UnsupportedProvider:
context.Errors.Add(String.Empty, S["The provided database provider is not supported."]);
break;
case DbConnectionValidatorResult.InvalidConnection:
context.Errors.Add(String.Empty, S["The provided connection string is invalid or server is unreachable."]);
break;
case DbConnectionValidatorResult.DocumentTableFound:
context.Errors.Add(String.Empty, S["The provided database and table prefix are already in use."]);
break;
}

And also this piece of code :

using (var shellContext = await _shellContextFactory.CreateDescribedContextAsync(shellSettings, shellDescriptor))
{
await shellContext.CreateScope().UsingServiceScopeAsync(async scope =>
{
IStore store;
try
{
store = scope.ServiceProvider.GetRequiredService<IStore>();
}
catch (Exception e)
{
// Tables already exist or database was not found
// The issue is that the user creation needs the tables to be present,
// if the user information is not valid, the next POST will try to recreate the
// tables. The tables should be rolled back if one of the steps is invalid,
// unless the recipe is executing?
_logger.LogError(e, "An error occurred while initializing the datastore.");
context.Errors.Add(String.Empty, S["An error occurred while initializing the datastore: {0}", e.Message]);
return;
}

Isn't this the same verification ?

The idea behind is to remove the dependency over YesSql.

TFleury added a commit to Codinlab/OrchardCore that referenced this issue Nov 16, 2022
…in SetupService

Removes OrchardCore.Setup.Core dependency on YesSql.Abstractions
@Skrypt
Copy link
Contributor

Skrypt commented Nov 16, 2022

I think the second one will throw an exception instead of just testing if it actually works before moving forward.

@TFleury
Copy link
Contributor Author

TFleury commented Nov 16, 2022

They both add an error and return.

@Skrypt
Copy link
Contributor

Skrypt commented Nov 16, 2022

True, sorry I've read that code too quickly. Then we need to move the validations all in one place. I believe that the issue is that our DBConnectionValidator will not test if the Store was properly instantiated. This is why it is doing GetRequiredService.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants