Skip to content

sprites.services.get_service() constructs ServiceWithState with invalid service= keyword #19

@kstechly

Description

@kstechly

Constructor mismatch -- I assume at some point someone was thinking that ServiceWithState wouldn't just be a Service subclass? Anyway, this actually blocks using Services since right now the SDK crashes on every get_service() call.

Details
When the service parsing path runs through src/sprites/services.py, _parse_service_with_state() returns ServiceWithState(service=service, state=state), but src/sprites/types.py defines ServiceWithState as a dataclass inheriting flattened Service fields (name, cmd, args, needs, http_port) plus state. As a result, real calls like sprites.services.get_service() fail with TypeError: ServiceWithState.__init__() got an unexpected keyword argument 'service' instead of returning a parsed service object.

Reproduction:

import sprites.services as services
from sprites.sprite import Sprite


class FakeResponse:
    status_code = 200
    text = ""

    def json(self):
        return {
            "name": "web",
            "cmd": "python",
            "args": ["-m", "http.server"],
            "needs": [],
            "http_port": 8000,
            "state": {
                "name": "web",
                "status": "running",
            },
        }


class FakeHTTPClient:
    def get(self, url):
        return FakeResponse()


class FakeClient:
    base_url = "https://api.sprites.dev"
    http_client = FakeHTTPClient()


sprite = Sprite("demo", FakeClient())
services.get_service(sprite, "web")

Traceback:

Traceback (most recent call last):
  File "/tmp/repro_service.py", line 34, in <module>
    services.get_service(sprite, "web")
  File "/Users/kaya/src/sprites-py/src/sprites/services.py", line 187, in get_service
    return _parse_service_with_state(response.json())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/kaya/src/sprites-py/src/sprites/services.py", line 103, in _parse_service_with_state
    return ServiceWithState(service=service, state=state)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: ServiceWithState.__init__() got an unexpected keyword argument 'service'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions