Midnighter/structurizr-python

failed to put_workspace

mcvulin opened this issue · 5 comments

Problem description

Please explain:

  • what you tried to achieve,
    I have I freshly created workspace at structurizr, and used your getting started example to build a basic workspace. I then worked out the environment variables required from your unit tests in order to specify my workspace and appropriate keys (hidden in my attached stack trace)

I expected to see the getting started diagrams in my new workspace on successful call of put_workspace, but the call fails with the attached callstack.

Code Sample

The following is shows what I changed in getting started to push up the workspace:

if __name__ == "__main__":
    logging.basicConfig(level="INFO")
    ws = main()
    settings = StructurizrClientSettings()
    ws.id = settings.workspace_id
    structurizr.show_versions()
    print(settings)
    scli = StructurizrClient(settings=settings)
    scli.put_workspace(ws)

/home/mjc/code/python/architecture/venv/bin/python /home/mjc/code/python/architecture/getting_started.py

System Information
==================
OS                  Linux
OS-release 5.6.15-arch1-1
Python              3.8.3

Package Versions
================
depinfo              1.5.3
httpx               0.13.3
pip                 20.1.1
pydantic             1.5.1
python-dotenv       0.13.0
setuptools          47.1.1
structurizr-python 0.0.1a1
url=HttpUrl('https://api.structurizr.com', scheme='https', host='api.structurizr.com', tld='com', host_type='domain') workspace_id=***** api_key=UUID('****') api_secret=UUID('****') user='**@**.**' agent='structurizr-python/0.0.1a1' workspace_archive_location=PosixPath('/home/mjc/code/python/architecture')
Traceback (most recent call last):
  File "/home/mjc/code/python/architecture/getting_started.py", line 69, in <module>
    scli.put_workspace(ws)
  File "/home/mjc/.local/lib/python3.8/site-packages/structurizr/api/structurizr_client.py", line 161, in put_workspace
    workspace_json = ws_io.json(by_alias=True, exclude_none=True)
  File "/home/mjc/.local/lib/python3.8/site-packages/structurizr/base_model.py", line 79, in json
    return super().json(
  File "pydantic/main.py", line 423, in pydantic.main.BaseModel.json
  File "/home/mjc/.local/lib/python3.8/site-packages/structurizr/base_model.py", line 55, in dict
    return super().dict(
  File "pydantic/main.py", line 386, in pydantic.main.BaseModel.dict
  File "pydantic/main.py", line 698, in _iter
  File "pydantic/main.py", line 755, in pydantic.main.BaseModel.__eq__
  File "/home/mjc/.local/lib/python3.8/site-packages/structurizr/base_model.py", line 55, in dict
    return super().dict(
  File "pydantic/main.py", line 386, in pydantic.main.BaseModel.dict
  File "pydantic/main.py", line 706, in _iter
  File "pydantic/main.py", line 639, in pydantic.main.BaseModel._get_value
  File "pydantic/main.py", line 640, in genexpr
  File "pydantic/main.py", line 607, in pydantic.main.BaseModel._get_value
  File "/home/mjc/.local/lib/python3.8/site-packages/structurizr/model/model_item.py", line 58, in dict
    obj["tags"] = ",".join(obj["tags"])
KeyError: 'tags'

Process finished with exit code 1

Context

See output above.

Hi @mcvulin, thanks for the report. Please be aware that this package is in very early alpha state. That said, we need to handle the case when no tags are present. Also, we should add the default tags as required by Structurizr to every element.

Understood, my hope is that this report helps. I would expect most people who want to use python with structurizr to do something similar as a first step.

Absolutely 🙂 my goal was definitely to support the getting started workspace interaction but I wasn't careful enough.

@mcvulin a bit off-topic: I didn't consider users printing the settings before. Do you think that certain information should be made secret by default, i.e., masked in output? This is certainly possible with pydantic.

Fixed the tag problem but there's still another issue.