-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
TESTING EXTERNAL SCRIPT: external merge request from Contributor #36603
base: release
Are you sure you want to change the base?
Conversation
…g-mssql-configuration' into external-contri/Issue-#24726/feat-wrong-mssql-configuration $ the commit. Merge changes from contributor for issue #24726 regarding MSSQL configuration fix
…tion' of https://github.com/appsmithorg/appsmith into external-contri/Issue-#24726/feat-wrong-mssql-configuration
…smith into external-contri/Issue-#24726/feat-wrong-mssql-configuration
…smith into external-contri/Issue-#24726/feat-wrong-mssql-configuration
…smith into external-contri/Issue-#24726/feat-wrong-mssql-configuration
…smith into external-contri/Issue-#24726/feat-wrong-mssql-configuration
…contri/Issue-#24726/feat-wrong-mssql-configuration' into chore/external-contribution-34472
WalkthroughThe pull request introduces several enhancements to the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant MssqlPlugin
participant MssqlPluginExecutor
User->>MssqlPlugin: Request to connect
MssqlPlugin->>MssqlPluginExecutor: Validate datasource configuration
MssqlPluginExecutor->>MssqlPluginExecutor: Check connection mode
MssqlPluginExecutor->>MssqlPluginExecutor: Validate endpoints
MssqlPluginExecutor->>MssqlPluginExecutor: Validate authentication
MssqlPluginExecutor-->>MssqlPlugin: Return validation results
MssqlPlugin-->>User: Connection status
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (6)
app/server/appsmith-plugins/mssqlPlugin/src/test/java/com/external/plugins/MssqlPluginTest.java (4)
238-253
: Well done, class! This test method looks good.The test effectively checks for null credentials in the datasource configuration. It's checking all the important aspects: username, password, and database name.
However, to make it even better, consider adding an assertion for the size of the
expectedOutput
set. This would ensure that only the expected number of error messages are returned.Here's a suggested addition to improve the test:
Set<String> expectedOutput = mssqlPluginExecutor.validateDatasource(dsConfig); +assertEquals(3, expectedOutput.size(), "Expected exactly 3 error messages"); assertTrue(expectedOutput.contains(MssqlErrorMessages.DS_MISSING_USERNAME_ERROR_MSG)); assertTrue(expectedOutput.contains(MssqlErrorMessages.DS_MISSING_PASSWORD_ERROR_MSG)); assertTrue(expectedOutput.contains(MssqlErrorMessages.DS_MISSING_DATABASE_NAME_ERROR_MSG));
255-262
: Good job! This test method is short and sweet.The test effectively checks for a null endpoint in the datasource configuration. It's focused and to the point.
To maintain consistency with the previous test, consider adding an assertion for the size of the
output
set.Here's a suggested addition to improve the test:
Set<String> output = mssqlPluginExecutor.validateDatasource(dsConfig); +assertEquals(1, output.size(), "Expected exactly 1 error message"); assertTrue(output.contains(MssqlErrorMessages.DS_MISSING_ENDPOINT_ERROR_MSG));
264-271
: Excellent work! This test method is clear and focused.The test effectively checks for an empty host in the datasource configuration. It's a good practice to test edge cases like this.
As with the previous tests, let's add an assertion for the size of the
output
set to maintain consistency.Here's a suggested addition to improve the test:
Set<String> output = mssqlPluginExecutor.validateDatasource(dsConfig); +assertEquals(1, output.size(), "Expected exactly 1 error message"); assertTrue(output.contains(MssqlErrorMessages.DS_MISSING_HOSTNAME_ERROR_MSG));
273-280
: Very good, students! This test method is concise and effective.The test correctly checks for null authentication in the datasource configuration. It's important to test these edge cases.
To maintain consistency with the other tests we've reviewed, let's add an assertion for the size of the
output
set.Here's a suggested addition to improve the test:
Set<String> output = mssqlPluginExecutor.validateDatasource(dsConfig); +assertEquals(1, output.size(), "Expected exactly 1 error message"); assertTrue(output.contains(MssqlErrorMessages.DS_MISSING_AUTHENTICATION_DETAILS_ERROR_MSG));
app/server/appsmith-plugins/mssqlPlugin/src/main/java/com/external/plugins/MssqlPlugin.java (2)
541-548
: Consider generalizing the CRUD template adjustment.Overriding
sanitizeGenerateCRUDPageTemplateInfo
to modify the select query for MSSQL syntax is effective but specific to this plugin.To improve extensibility, consider abstracting this logic into a common utility or configuration that can be reused across different database plugins. This approach will reduce code duplication and simplify maintenance.
Line range hint
598-687
: Simplify the connection pool creation logic for clarity.The
createConnectionPool
method contains deeply nested blocks and extensive exception handling, which can make the code harder to read and maintain.Refactoring the method to reduce nesting and using helper methods for exception handling can improve readability. For instance, you could extract the SQLState-to-error-message mapping into a separate method or utilize a mapping structure like a
Map<String, String>
for cleaner code.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (4)
- app/server/appsmith-plugins/mssqlPlugin/pom.xml (1 hunks)
- app/server/appsmith-plugins/mssqlPlugin/src/main/java/com/external/plugins/MssqlPlugin.java (12 hunks)
- app/server/appsmith-plugins/mssqlPlugin/src/main/java/com/external/plugins/exceptions/MssqlErrorMessages.java (1 hunks)
- app/server/appsmith-plugins/mssqlPlugin/src/test/java/com/external/plugins/MssqlPluginTest.java (3 hunks)
🔇 Additional comments (6)
app/server/appsmith-plugins/mssqlPlugin/src/main/java/com/external/plugins/exceptions/MssqlErrorMessages.java (1)
29-30
: Class, pay attention to these new error messages!Well done on adding these new error messages! They're like signposts guiding our users to provide the correct information. Let's break it down:
DS_MISSING_HOSTNAME_ERROR_MSG
: This tells users they can't leave the host value empty. It's like reminding students to write their names on their homework!
DS_MISSING_DATABASE_NAME_ERROR_MSG
: This alerts users when they forget to specify the database name. It's similar to asking students which subject their homework is for!These additions will help users understand exactly what's missing in their datasource configuration. It's like giving clear instructions before an exam - it helps everyone perform better!
app/server/appsmith-plugins/mssqlPlugin/pom.xml (1)
Line range hint
18-23
: Excellent addition, class! Let's discuss the importance of this new dependency.Students, pay attention to this new addition to our project's dependencies. The Microsoft SQL Server JDBC driver is a crucial component that allows our application to communicate effectively with Microsoft SQL Server databases.
Let's break it down:
- GroupId: com.microsoft.sqlserver
- ArtifactId: mssql-jdbc
- Version: 11.2.1.jre17
This version is quite recent, which is commendable. It ensures we're using up-to-date features and security patches. Remember, always strive to use the latest stable versions in your projects!
app/server/appsmith-plugins/mssqlPlugin/src/test/java/com/external/plugins/MssqlPluginTest.java (1)
238-280
: Class, I'm impressed with your work on these new test methods!You've done an excellent job adding test coverage for various edge cases in datasource configuration validation. Each test is focused, clear, and effective. The consistent structure across all tests makes them easy to read and understand.
To make these tests even better, consider implementing the suggested improvements for consistency:
- Add assertions for the expected size of the error message set in each test.
- Ensure consistent naming of variables (e.g.,
expectedOutput
vsoutput
).Keep up the good work! These tests will help ensure the robustness of the MssqlPlugin.
app/server/appsmith-plugins/mssqlPlugin/src/main/java/com/external/plugins/MssqlPlugin.java (3)
32-32
: Excellent inclusion ofSQLServerException
for specific error handling.By importing
com.microsoft.sqlserver.jdbc.SQLServerException
, you enable handling SQL Server-specific exceptions more precisely, which improves the granularity of your error handling.
396-400
: Great job modularizing the validation logic.By extracting
validateConnectionMode
,validateEndpoints
, andvalidateAuthentication
into separate methods, you've improved the readability and maintainability of thevalidateDatasource
method. This approach enhances code organization and makes future updates easier.
652-687
: Review the SQLState codes for accurate exception mapping.Mapping SQLState codes to specific error messages improves user feedback. However, some SQLState codes used may not correspond to the intended errors.
Please verify that the SQLState codes used match the appropriate error conditions. For example, SQLState
"08S02"
typically indicates a "Duplicate cursor name," which might not align with "Could not connect to server."Run the following script to confirm the SQLState codes and their meanings:
Ensuring the correct SQLState codes are used will enhance the accuracy of error reporting.
import static com.appsmith.external.exceptions.pluginExceptions.BasePluginErrorMessages.CONNECTION_CLOSED_ERROR_MSG; | ||
import static com.appsmith.external.exceptions.pluginExceptions.BasePluginErrorMessages.CONNECTION_INVALID_ERROR_MSG; | ||
import static com.appsmith.external.exceptions.pluginExceptions.BasePluginErrorMessages.CONNECTION_NULL_ERROR_MSG; |
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.
Avoid redundant imports of connection error messages.
You have imported CONNECTION_CLOSED_ERROR_MSG
, CONNECTION_INVALID_ERROR_MSG
, and CONNECTION_NULL_ERROR_MSG
from both com.appsmith.external.exceptions.pluginExceptions.BasePluginErrorMessages
and com.external.plugins.exceptions.MssqlErrorMessages
. This redundancy could lead to confusion and potential conflicts in error messaging.
Consider consolidating these constants into a single source or ensuring you import them from only one class to maintain clarity and prevent redundancy.
// The function can throw either StaleConnectionException or SQLException. The | ||
// underlying | ||
// hikari | ||
// library throws SQLException in case the pool is closed or there is an issue initializing | ||
// the connection pool which can also be translated in our world to StaleConnectionException | ||
// library throws SQLException in case the pool is closed or there is an issue | ||
// initializing | ||
// the connection pool which can also be translated in our world to | ||
// StaleConnectionException |
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.
🛠️ Refactor suggestion
Enhance exception handling for better specificity.
Wrapping all SQLException
instances that are not StaleConnectionException
into a StaleConnectionException
may obscure the original cause of the exception. This could make debugging more challenging.
Consider handling specific SQLException
subtypes separately to preserve the original exception information. For instance, you might catch SQLTransientConnectionException
for transient issues while allowing other exceptions to propagate with their original messages.
private void validateConnectionMode(DatasourceConfiguration datasourceConfiguration, Set<String> invalids) { | ||
if (datasourceConfiguration.getConnection() != null | ||
&& datasourceConfiguration.getConnection().getMode() == null) { | ||
invalids.add(MssqlErrorMessages.DS_MISSING_CONNECTION_MODE_ERROR_MSG); | ||
} | ||
} |
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.
Ensure null connection configurations are properly handled.
In validateConnectionMode
, if datasourceConfiguration.getConnection()
is null
, no error is added to invalids
. This might lead to scenarios where missing connection configurations go unnoticed.
Consider adding a null check and an appropriate error message:
if (datasourceConfiguration.getConnection() == null) {
invalids.add(MssqlErrorMessages.DS_MISSING_CONNECTION_CONFIGURATION_ERROR_MSG);
return;
}
This change will ensure that users are alerted when the connection configuration is missing entirely.
Description
Fixes #
Warning
If no issue exists, please create an issue first, and check with the maintainers if the issue is valid.
Automation
/ok-to-test tags="@tag.Sanity, @tag.Datasource"
🔍 Cypress test results
Tip
🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/11100987656
Commit: b269ee6
Cypress dashboard.
Tags:
@tag.Sanity, @tag.Datasource
Spec:
Mon, 30 Sep 2024 07:47:11 UTC
Communication
Should the DevRel and Marketing teams inform users about this change?
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
Tests