Skip to content

Value Expression DB Query fixes#4257

Merged
Maheshkale447 merged 3 commits into
Releases/Official-Releasefrom
BugFix/ValueExpressionDBQuery
Jul 21, 2025
Merged

Value Expression DB Query fixes#4257
Maheshkale447 merged 3 commits into
Releases/Official-Releasefrom
BugFix/ValueExpressionDBQuery

Conversation

@GokulBothe99

@GokulBothe99 GokulBothe99 commented Jul 21, 2025

Copy link
Copy Markdown
Contributor

Thank you for your contribution.
Before submitting this PR, please make sure:

  • PR description and commit message should describe the changes done in this PR
  • Verify the PR is pointing to correct branch i.e. Release or Beta branch if the code fix is for specific release , else point it to master
  • Latest Code from master or specific release branch is merged to your branch
  • No unwanted\commented\junk code is included
  • No new warning upon build solution
  • Code Summary\Comments are added to my code which explains what my code is doing
  • Existing unit test cases are passed
  • New Unit tests are added for your development
  • Sanity Tests are successfully executed for New and Existing Functionality
  • Verify that changes are compatible with all relevant browsers and platforms.
  • After creating pull request there should not be any conflicts
  • Resolve all Codacy comments
  • Builds and checks are passed before PR is sent for review
  • Resolve code review comments
  • Update the Help Library document to match any feature changes

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling and messaging when processing environment database queries in the value expression editor.
    • Enhanced query validation and feedback for unsupported or invalid database queries.
  • Style

    • Updated help text titles and category labels in the value expression editor for better clarity.

@coderabbitai

coderabbitai Bot commented Jul 21, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The changes update the help text in the value expression editor UI to clarify database query support and refactor the ReplaceEnvDBWithValue method for improved error handling, query parsing, and limit enforcement. The refactoring introduces more precise regex parsing, better exception management, and enhanced handling of SQL query limits for different database types.

Changes

File(s) Change Summary
Ginger/Ginger/ValueExpression/ValueExpressionEditorPage.xaml.cs Updated help text title and category for environment database item selection in the editor UI.
Ginger/GingerCoreNET/ValueExpressionLib/ValueExpression.cs Refactored ReplaceEnvDBWithValue for improved error handling, regex parsing, and limit logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ValueExpressionEditorPage
    participant ValueExpression
    participant Logger

    User->>ValueExpressionEditorPage: Selects Env DB item
    ValueExpressionEditorPage->>User: Shows updated help text

    User->>ValueExpression: Triggers ReplaceEnvDBWithValue
    ValueExpression->>ValueExpression: Parse input with regex
    ValueExpression->>ValueExpression: Validate parameters
    alt Error detected
        ValueExpression->>Logger: Log error
        ValueExpression->>User: Return error message in value
    else Valid input
        ValueExpression->>ValueExpression: Clean and adjust query
        ValueExpression->>ValueExpression: Add/adjust LIMIT or FETCH clause
        ValueExpression->>User: Return DB query result
    end
Loading

Estimated code review effort

2 (10–30 minutes)

Suggested reviewers

  • Maheshkale447
  • prashelke

Poem

A nibble here, a tweak or two,
The queries now are crisp and new.
If limits wander, we rein them in tight,
And help text now shines, clear and bright.
With regex and care, we hop through the code—
Another fine patch for the burrow’s abode! 🥕

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch BugFix/ValueExpressionDBQuery

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2ec2cfe and 74c059e.

📒 Files selected for processing (2)
  • Ginger/Ginger/ValueExpression/ValueExpressionEditorPage.xaml.cs (1 hunks)
  • Ginger/GingerCoreNET/ValueExpressionLib/ValueExpression.cs (4 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: GokulBothe99
PR: Ginger-Automation/Ginger#4245
File: Ginger/GingerCoreNET/ValueExpressionLib/ValueExpression.cs:1533-1535
Timestamp: 2025-07-09T14:46:34.133Z
Learning: In the ValueExpression.cs ReplaceEnvDBWithValue() method, error cases that return without replacing the original expression in mValueCalculated are intentional behavior and working as expected, rather than being inconsistent error handling that should be fixed.
Learnt from: manas-droid
PR: Ginger-Automation/Ginger#3389
File: Ginger/GingerCoreNET/DataSource/LiteDBSQLTranslator.cs:139-141
Timestamp: 2024-07-26T22:04:12.930Z
Learning: The user has clarified that the SQL command in the `ValueExpressionForAddRow` method of `LiteDBSQLTranslator.cs` is for representation purposes only and is not used in the "AddRow" section of the `LiteDB.cs` file.
Ginger/Ginger/ValueExpression/ValueExpressionEditorPage.xaml.cs (8)

Learnt from: GokulBothe99
PR: #4245
File: Ginger/GingerCoreNET/ValueExpressionLib/ValueExpression.cs:1533-1535
Timestamp: 2025-07-09T14:46:34.133Z
Learning: In the ValueExpression.cs ReplaceEnvDBWithValue() method, error cases that return without replacing the original expression in mValueCalculated are intentional behavior and working as expected, rather than being inconsistent error handling that should be fixed.

Learnt from: GokulBothe99
PR: #4226
File: Ginger/GingerCoreCommon/Repository/BusinessFlowLib/BusinessFlow.cs:234-238
Timestamp: 2025-06-13T12:50:36.132Z
Learning: In the Ginger codebase, the [AllowUserToEdit("<Label>")] attribute is intentionally supplied with a string that represents the display label (e.g., "Description", "Active"), not a default value. Suggestions to remove or change this parameter should be avoided unless the label itself is incorrect.

Learnt from: GokulBothe99
PR: #4245
File: Ginger/Ginger/UserControlsLib/UCDataMapping.xaml.cs:658-667
Timestamp: 2025-07-09T13:44:51.210Z
Learning: In UCDataMapping.xaml.cs SetDatabaseValues() method, the line xDBValueExpression.Visibility = Visibility.Visible is intentionally set unconditionally and works correctly with the visibility logic in SetValueControlsView(). This is the expected behavior per user confirmation.

Learnt from: prashelke
PR: #4249
File: Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs:7199-7202
Timestamp: 2025-07-10T07:12:52.786Z
Learning: In Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs, text values used in XPath expressions should be escaped using a helper method (such as EscapeXPathString) to handle single quotes and ensure valid XPath syntax.

Learnt from: prashelke
PR: #4254
File: Ginger/Ginger/ApplicationModelsLib/POMModels/POMWizardLib/LearnWizard/POMLearnConfigWizardPage.xaml.cs:70-73
Timestamp: 2025-07-16T14:42:32.219Z
Learning: In Ginger/Ginger/ApplicationModelsLib/POMModels/POMWizardLib/LearnWizard/POMLearnConfigWizardPage.xaml.cs, prashelke prefers to keep the current !WorkSpace.Instance.BetaFeatures.ShowPOMForAI logic for binding and showing AI POM controls, rather than changing it to positive logic.

Learnt from: manas-droid
PR: #3389
File: Ginger/GingerCoreNET/DataSource/LiteDBSQLTranslator.cs:139-141
Timestamp: 2024-07-26T22:04:12.930Z
Learning: The user has clarified that the SQL command in the ValueExpressionForAddRow method of LiteDBSQLTranslator.cs is for representation purposes only and is not used in the "AddRow" section of the LiteDB.cs file.

Learnt from: GokulBothe99
PR: #4245
File: Ginger/Ginger/UserControlsLib/UCDataMapping.xaml.cs:230-234
Timestamp: 2025-07-09T13:45:55.367Z
Learning: In UCDataMapping.xaml.cs ValueExpression binding code, using WorkSpace.Instance.SolutionRepository.GetAllRepositoryItems().FirstOrDefault() without null checks for the mContext creation is intentional and working as expected per user confirmation.

Learnt from: prashelke
PR: #4249
File: Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs:4684-4695
Timestamp: 2025-07-10T07:11:28.974Z
Learning: In Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs, attribute values used in CSS selectors (e.g., ByTitle, ByAriaLabel, ByDataTestId, ByPlaceholder) should be escaped using a helper method (such as EscapeCssAttributeValue) to prevent selector breakage due to special characters.

Ginger/GingerCoreNET/ValueExpressionLib/ValueExpression.cs (13)

Learnt from: GokulBothe99
PR: #4245
File: Ginger/GingerCoreNET/ValueExpressionLib/ValueExpression.cs:1533-1535
Timestamp: 2025-07-09T14:46:34.133Z
Learning: In the ValueExpression.cs ReplaceEnvDBWithValue() method, error cases that return without replacing the original expression in mValueCalculated are intentional behavior and working as expected, rather than being inconsistent error handling that should be fixed.

Learnt from: prashelke
PR: #4249
File: Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs:7199-7202
Timestamp: 2025-07-10T07:12:52.786Z
Learning: In Ginger/GingerCoreNET/Drivers/CoreDrivers/Web/Selenium/SeleniumDriver.cs, text values used in XPath expressions should be escaped using a helper method (such as EscapeXPathString) to handle single quotes and ensure valid XPath syntax.

Learnt from: IamRanjeetSingh
PR: #3897
File: Ginger/GingerCoreNET/Telemetry/TelemetryQueue.cs:155-186
Timestamp: 2024-09-16T10:13:19.599Z
Learning: In this codebase, methods prefixed with Try (e.g., TryAddToDBAsync, TrySendToCollectorAsync, TryDeleteRecordsFromDBAsync) internally handle exceptions, so additional exception handling in the calling methods is unnecessary.

Learnt from: manas-droid
PR: #3389
File: Ginger/GingerCoreNET/DataSource/LiteDBSQLTranslator.cs:139-141
Timestamp: 2024-07-26T22:04:12.930Z
Learning: The user has clarified that the SQL command in the ValueExpressionForAddRow method of LiteDBSQLTranslator.cs is for representation purposes only and is not used in the "AddRow" section of the LiteDB.cs file.

Learnt from: GokulBothe99
PR: #4188
File: Ginger/GingerCoreNET/RunLib/CLILib/DoOptionsHanlder.cs:22-23
Timestamp: 2025-04-25T13:29:45.059Z
Learning: The using Amdocs.Ginger.Repository; statement in Ginger/GingerCoreNET/RunLib/CLILib/DoOptionsHanlder.cs is necessary as it provides access to the ObservableList<> class which is used throughout the file for collections of RunSetConfig, AnalyzerItemBase, and ApplicationPOMModel objects.

Learnt from: GokulBothe99
PR: #4188
File: Ginger/GingerCoreNET/RunLib/CLILib/DoOptionsHanlder.cs:22-23
Timestamp: 2025-04-25T13:29:45.059Z
Learning: The using Amdocs.Ginger.Repository; statement in Ginger/GingerCoreNET/RunLib/CLILib/DoOptionsHanlder.cs is necessary as it imports the ObservableList<> class which is used throughout the file.

Learnt from: prashelke
PR: #4232
File: Ginger/GingerCoreNET/ActionsLib/UI/VisualTesting/VRTAnalyzer.cs:19-22
Timestamp: 2025-06-16T10:37:13.073Z
Learning: In Ginger codebase, both using amdocs.ginger.GingerCoreNET; and using Amdocs.Ginger.CoreNET; are valid and serve different purposes. The first (lowercase) contains the WorkSpace class and related workspace functionality, while the second (proper case) contains drivers like GenericAppiumDriver and other core functionality. Both may be required in files that use types from both namespaces.

Learnt from: GokulBothe99
PR: #3909
File: Ginger/Ginger/RunSetPageLib/NewRunSetPage.xaml.cs:2328-2346
Timestamp: 2024-09-16T16:34:20.667Z
Learning: In NewRunSetPage.xaml.cs, the methods GenerateHTMLReportFromRemote() and GenerateHTMLReportFromLocal() are kept separate because the application first tries to load remote data, and if not found, it falls back to loading local data.

Learnt from: GokulBothe99
PR: #4085
File: Ginger/GingerCoreNET/SourceControl/GITSourceControl.cs:1353-1391
Timestamp: 2025-02-06T07:17:40.793Z
Learning: In the Ginger project, exceptions during Git operations are logged to file through the Reporter system, which is the preferred error handling approach.

Learnt from: GokulBothe99
PR: #4137
File: Ginger/Ginger/SourceControl/SourceControlProjectsPage.xaml.cs:21-21
Timestamp: 2025-03-20T11:10:30.816Z
Learning: The Amdocs.Ginger.Common.SourceControlLib namespace is required in files that reference the GingerSolution class for source control operations in the Ginger automation framework.

Learnt from: GokulBothe99
PR: #4137
File: Ginger/Ginger/SourceControl/SourceControlProjectsPage.xaml.cs:21-21
Timestamp: 2025-03-20T11:10:33.780Z
Learning: The Amdocs.Ginger.Common.SourceControlLib namespace is required in files that reference the GingerSolution class for source control operations in the Ginger automation framework.

Learnt from: prashelke
PR: #3984
File: Ginger/GingerCoreNET/ALMLib/RQM/ExportToRQM.cs:911-911
Timestamp: 2024-11-06T09:06:34.050Z
Learning: In the Ginger/GingerCoreNET/ALMLib/RQM/ExportToRQM.cs file of the Ginger project, initializing lists in C# using [] syntax (e.g., List<T> list = [];) is acceptable and does not require changing to new List<T>().

Learnt from: GokulBothe99
PR: #4245
File: Ginger/Ginger/Actions/ActionEditPages/ValidationDBPage.xaml.cs:195-197
Timestamp: 2025-07-09T13:49:32.217Z
Learning: In ValidationDBPage.xaml.cs GetValue() method, logging validation errors and returning an empty string when validation fails is the intended behavior and working as expected, rather than throwing exceptions or using result objects.

🔇 Additional comments (11)
Ginger/Ginger/ValueExpression/ValueExpressionEditorPage.xaml.cs (1)

639-639: LGTM! Improved help text clarity.

The change from "Fetch Data From Database" to "Only select query supported." better reflects the actual functionality constraints, and changing the category from "Sample" to "Syntax" is more semantically appropriate for the content being displayed.

Ginger/GingerCoreNET/ValueExpressionLib/ValueExpression.cs (10)

28-28: LGTM - Using statement addition looks appropriate.

The addition of using GingerCore.Actions; appears to be necessary for the refactored functionality.


1532-1535: Improved input validation with explicit exception throwing.

The change from early returns to throwing InvalidDataException for null/empty input provides clearer error handling and makes validation failures more explicit.


1537-1545: Excellent regex consolidation and parsing improvement.

The consolidated regex pattern @"\{EnvApp=(.*?)\s+EnvAppDB=(.*?)\s+Query=(.*)\}" with proper group extraction is much cleaner than multiple separate regex matches. The use of named groups through Groups[1].Value, Groups[2].Value, and Groups[3].Value makes the code more readable and maintainable.


1547-1556: Clear validation logic with descriptive error messages.

The validation for environment application and database existence with specific error messages like "Application '{envApp}' not found." and "Database '{envAppDB}' not found." provides much better debugging information than the previous implementation.


1557-1563: Good SQL query type validation.

The validation that ensures only SELECT queries are allowed for SQL databases aligns with the help text changes mentioned in the AI summary and provides appropriate security constraints.


1564-1565: Query string cleaning and limit enforcement.

The query cleaning logic replacing escaped characters and the automatic addition of single record limits is a good enhancement for consistency and performance.


1582-1587: Note: Behavior change in error handling approach.

This refactoring changes the error handling behavior from the previous approach. According to retrieved learnings, the original method's pattern of returning without replacing the original expression in mValueCalculated was intentional. The new approach embeds error messages directly in the calculated value by replacing the original expression with error strings.

This change appears to be intentional and provides better user feedback, but it's worth confirming this aligns with the intended behavior change.


1606-1624: Well-implemented MySQL/PostgreSQL LIMIT handling.

The logic correctly:

  • Detects existing LIMIT clauses with @"\bLIMIT\s+(\d+)\b"
  • Replaces limits > 1 with "LIMIT 1" while preserving smaller limits
  • Properly handles trailing semicolons by checking query.EndsWith(";")
  • Uses appropriate string manipulation with Substring and TrimEnd()

The implementation handles the most common cases correctly.


1627-1633: Correct TOP clause handling for SQL Server/Access.

The implementation properly:

  • Checks for existing TOP 1 clauses to avoid duplication
  • Uses regex replacement "SELECT TOP 1" with case-insensitive matching
  • Handles the SQL Server/MS Access syntax correctly

This approach is clean and follows SQL standards.


1637-1648: Proper Oracle/DB2 FETCH FIRST implementation.

The logic correctly:

  • Detects existing FETCH FIRST 1 ROWS ONLY clauses
  • Handles trailing semicolons appropriately
  • Uses the standard SQL FETCH FIRST syntax for Oracle and DB2
  • Maintains query integrity with proper string manipulation

The implementation follows database-specific standards correctly.

Comment on lines +1649 to +1655

default:
break;
}

return query;
}

}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Consider adding handling for unsupported database types.

While the default case currently does nothing, consider logging a warning or informational message for unsupported database types to aid in debugging and future maintenance.

 default:
+    Reporter.ToLog(eLogLevel.DEBUG, $"No single record limit applied for database type: {dbType}");
     break;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
default:
break;
}
return query;
}
}
default:
Reporter.ToLog(eLogLevel.DEBUG, $"No single record limit applied for database type: {dbType}");
break;
}
return query;
}
🤖 Prompt for AI Agents
In Ginger/GingerCoreNET/ValueExpressionLib/ValueExpression.cs around lines 1649
to 1655, the default case in the switch statement does not handle unsupported
database types. Add a logging statement in the default case to warn or inform
about unsupported database types, which will help with debugging and future
maintenance.

@Maheshkale447
Maheshkale447 merged commit 09747a5 into Releases/Official-Release Jul 21, 2025
4 of 5 checks passed
@Maheshkale447
Maheshkale447 deleted the BugFix/ValueExpressionDBQuery branch July 21, 2025 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants