fix(remote_services): immediate result codes were collapsed to UNKNOWN - #92
Merged
Merged
Conversation
When `_send_command` got a terminal result with no `status_id`, it
called `RemoteServiceStatus(result_code)` with a bare string
("PERFORMED", "ERROR", ...). The constructor then ran
`if "status" in response:` on that string — a string-in-string check
that is False for these codes — so `state` silently fell through to
ExecutionState.UNKNOWN. Callers had no way to distinguish a successful
remote action from a server timeout.
Two changes:
1. `_send_command` (`remote_services.py:299`): wrap the bare code in the
same dict shape the polling endpoint returns so the constructor
extracts it through the existing path:
RemoteServiceStatus({"status": {"result": result_code}})
2. `RemoteServiceStatus.__init__`: guard with `isinstance(response, dict)`
and tolerate result codes outside the ExecutionState enum (e.g. a
future "REJECTED") with a try/except ValueError — falling back to
UNKNOWN instead of crashing during construction.
Concrete repro (no test infra needed):
>>> from pyporscheconnectapi.remote_services import (
... RemoteServiceStatus, ExecutionState,
... )
>>> # Before this patch: silent UNKNOWN.
>>> # After:
>>> s = RemoteServiceStatus({"status": {"result": "PERFORMED"}})
>>> s.state == ExecutionState.PERFORMED
True
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Removed comments clarifying response structure and error handling.
Removed comments explaining result handling for immediate results.
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.
When
_send_commandgot a terminal result with nostatus_id, it calledRemoteServiceStatus(result_code)with a bare string ("PERFORMED", "ERROR", ...). The constructor then ranif "status" in response:on that string — a string-in-string check that is False for these codes — sostatesilently fell through to ExecutionState.UNKNOWN. Callers had no way to distinguish a successful remote action from a server timeout.Two changes:
_send_command(remote_services.py:299): wrap the bare code in the same dict shape the polling endpoint returns so the constructor extracts it through the existing path:RemoteServiceStatus.__init__: guard withisinstance(response, dict)and tolerate result codes outside the ExecutionState enum (e.g. a future "REJECTED") with a try/except ValueError — falling back to UNKNOWN instead of crashing during construction.Concrete repro (no test infra needed):