Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Currently cannot cast from dict to Model #175

Open
smurf-cm opened this issue Jun 27, 2022 · 0 comments
Open

Currently cannot cast from dict to Model #175

smurf-cm opened this issue Jun 27, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@smurf-cm
Copy link
Contributor

Here's some example code to replicate the issue.

from __future__ import annotations
import tinychain as tc 

URI = tc.URI("http://127.0.0.1:8702/demo")


class User(tc.app.Model):
    __uri__ = URI.append("user")

    username = tc.Column("username", tc.String, 100)

    def __init__(self, username):
        self.username = username


class UserService(tc.graph.Graph):
    __uri__ = URI

    @tc.post
    def create_user(self, new_user: User) -> tc.Number:
        user_id = self.user.max_id() + 1
        return tc.After(
            self.user.insert([user_id], [new_user.username]),
            user_id
        )


def start_host(name, apps):
    from tests.tctest.process import start_local_host, start_docker

    # return start_local_host(name, apps)
    return start_docker(name, apps)


if __name__ == "__main__":
    host = start_host("demo", [UserService(models=[User])])
    host.post("/demo/create_user", {"username": "user"})

When running the above we get the following error:

Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/cormac/workspace/python/tinychain/script.py", line 43, in <module>
    assert host.post("/demo/create_user", {"username": "user"}) == 10
  File "/home/cormac/workspace/python/tinychain/client/tinychain/host.py", line 113, in post
    return self._handle(request)
  File "/home/cormac/workspace/python/tinychain/client/tinychain/host.py", line 48, in _handle
    raise BadRequest(response)
tinychain.error.BadRequest: {'/error/bad_request': {'message': 'cannot cast into type String from: (username, /state/scalar/value/string, 100)', 'stack': ['while resolving _return_when', 'in call to POST class http://127.0.0.1:8702/demo instance /create_user']}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant