refactor: validate backup retention days on SQL DB#249
Open
v-alexmoraru wants to merge 5 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds SQLDatabase-specific validation for the properties.backupRetentionDays field when using the fs set command, including a dedicated error message and test coverage.
Changes:
- Added
validate_sql_database_propertyto enforcebackupRetentionDaysinteger range validation. - Integrated SQLDatabase property validation into
fs setexecution for SQLDatabase items. - Added constants and an error message helper, plus unit tests for valid/invalid inputs.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_utils/test_fab_cmd_set_utils.py | Adds unit tests covering SQLDatabase backupRetentionDays validation scenarios. |
| src/fabric_cli/utils/fab_cmd_set_utils.py | Implements SQLDatabase-specific validator for backupRetentionDays. |
| src/fabric_cli/errors/common.py | Adds a dedicated error message for invalid backupRetentionDays. |
| src/fabric_cli/core/fab_constant.py | Introduces SQLDatabase validation constants (min/max days and property key). |
| src/fabric_cli/commands/fs/set/fab_fs_set_item.py | Hooks SQLDatabase property validation into the set command execution path. |
Comment on lines
+95
to
+136
| def validate_sql_database_property(query: str, input_value: str) -> None: | ||
| """Validate SQLDatabase-specific property values. | ||
|
|
||
| Args: | ||
| query: The property query path being set. | ||
| input_value: The input value to validate. | ||
|
|
||
| Raises: | ||
| FabricCLIError: If the value is invalid for the property. | ||
| """ | ||
| if query == fab_constant.SQL_DATABASE_BACKUP_RETENTION_PROPERTY: | ||
| min_days = fab_constant.SQL_DATABASE_BACKUP_RETENTION_MIN_DAYS | ||
| max_days = fab_constant.SQL_DATABASE_BACKUP_RETENTION_MAX_DAYS | ||
|
|
||
| try: | ||
| try: | ||
| value = int(input_value) | ||
| except ValueError: | ||
| # Fall back to JSON for encoded values like '7' or '"7"' | ||
| parsed = json.loads(input_value) | ||
| if isinstance(parsed, bool): | ||
| raise ValueError("Booleans are not valid integer values") | ||
| elif isinstance(parsed, int): | ||
| value = parsed | ||
| elif isinstance(parsed, str): | ||
| value = int(parsed) | ||
| else: | ||
| raise ValueError("Value must be an integer") | ||
|
|
||
| # Validate range | ||
| if not min_days <= value <= max_days: | ||
| raise ValueError("Out of range") | ||
|
|
||
| except (ValueError, TypeError, json.JSONDecodeError): | ||
| raise FabricCLIError( | ||
| CommonErrors.invalid_backup_retention_days( | ||
| str(input_value), | ||
| min_days, | ||
| max_days, | ||
| ), | ||
| fab_constant.ERROR_INVALID_INPUT, | ||
| ) |
Comment on lines
+113
to
+120
| # Fall back to JSON for encoded values like '7' or '"7"' | ||
| parsed = json.loads(input_value) | ||
| if isinstance(parsed, bool): | ||
| raise ValueError("Booleans are not valid integer values") | ||
| elif isinstance(parsed, int): | ||
| value = parsed | ||
| elif isinstance(parsed, str): | ||
| value = int(parsed) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.