fix: invalid state and TypeError bug in _AllowedDomainNames.valid_name#5050
fix: invalid state and TypeError bug in _AllowedDomainNames.valid_name#5050Copilot wants to merge 6 commits into
_AllowedDomainNames.valid_name#5050Conversation
Up to standards ✅🟢 Issues
|
… fix ZoneError call Agent-Logs-Url: https://github.com/ansys/pyfluent/sessions/a493dbab-5525-4799-8b10-b99c18923d8d Co-authored-by: Gobot1234 <50501825+Gobot1234@users.noreply.github.com>
_AllowedDomainNames.valid_name
…er PR #5048) Agent-Logs-Url: https://github.com/ansys/pyfluent/sessions/7cf80380-e40d-4804-b766-bab5a89d01f4 Co-authored-by: Gobot1234 <50501825+Gobot1234@users.noreply.github.com>
| ) | ||
|
|
||
|
|
||
| class DomainError(ValueError): |
There was a problem hiding this comment.
@prmukherj looks like ZoneError is defined above so I think the location of this exception should be fine
There was a problem hiding this comment.
Pull request overview
This PR fixes an exception-path bug in the solution variables domain validation helper so invalid/missing domain IDs reliably raise a proper, user-facing error (instead of triggering a TypeError). It also adds focused unit tests to prevent regressions related to issue #5042.
Changes:
- Add a new
DomainErrorexception type for invalid domain-name inputs. - Update
_AllowedDomainNames.valid_name()to return a domain ID when present and raiseDomainErrorwhen the ID cannot be resolved (including the priorTypeErrorscenario). - Add unit tests covering success,
0domain ID, missing domain ID, and invalid domain name.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/ansys/fluent/core/services/solution_variables.py |
Introduces DomainError and updates _AllowedDomainNames.valid_name() to avoid TypeError and to fail fast when domain_id is None. |
tests/test_solution_variables.py |
Adds unit tests validating _AllowedDomainNames.valid_name() behavior for valid/invalid domain names and missing IDs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
_AllowedDomainNames.valid_name_AllowedDomainNames.valid_name
| domain_id = self._zones_info.domain_id(domain_name) | ||
| if domain_id is not None: | ||
| return domain_id | ||
| raise DomainError( | ||
| domain_name=domain_name, | ||
| allowed_values=self(), | ||
| ) |
| class DomainError(ValueError): | ||
| """Exception class for errors in domain name.""" | ||
|
|
||
| def __init__(self, domain_name: str, allowed_values: List[str]): | ||
| """Initialize DomainError.""" | ||
| self.domain_name = domain_name | ||
| super().__init__( | ||
| allowed_name_error_message( | ||
| context="domain", trial_name=domain_name, allowed_values=allowed_values | ||
| ) | ||
| ) | ||
|
|
| with pytest.raises(DomainError): | ||
| allowed.valid_name("nonexistent") | ||
|
|
||
|
|
| @@ -0,0 +1 @@ | |||
| Invalid state and TypeError bug in \`_AllowedDomainNames.valid_name\` | |||
Fixes #5042 and adds a test to ensure can't happen