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

TypeError: Unexpected type for collection: <class 'str'> #4

Open
caufieldjh opened this issue Mar 3, 2023 · 1 comment
Open

TypeError: Unexpected type for collection: <class 'str'> #4

caufieldjh opened this issue Mar 3, 2023 · 1 comment

Comments

@caufieldjh
Copy link

I've been trying out the linkml-renderer with the b2ai-standards data and in most cases, it works very well. For some schemas (or some data?) it will throw a TypeError when rendering HTML, like this:

$ linkml-render -s src/schema/standards_schema_all.yaml -r UseCaseContainer -o test.html src/data/UseCase.yaml 
Traceback (most recent call last):
  File "/home/harry/b2ai-standards-registry/.venv/bin/linkml-render", line 8, in <module>
    sys.exit(main())
  File "/home/harry/b2ai-standards-registry/.venv/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/harry/b2ai-standards-registry/.venv/lib/python3.9/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/harry/b2ai-standards-registry/.venv/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/harry/b2ai-standards-registry/.venv/lib/python3.9/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/harry/b2ai-standards-registry/.venv/lib/python3.9/site-packages/linkml_renderer/cli.py", line 81, in main
    out = renderer.render(obj, sv, source_element_name=root)
  File "/home/harry/b2ai-standards-registry/.venv/lib/python3.9/site-packages/linkml_renderer/renderers/html_renderer.py", line 70, in render
    self.generate(element, ctxt)
  File "/home/harry/b2ai-standards-registry/.venv/lib/python3.9/site-packages/linkml_renderer/renderers/html_renderer.py", line 98, in generate
    return self.generate_document(element, context)
  File "/home/harry/b2ai-standards-registry/.venv/lib/python3.9/site-packages/linkml_renderer/renderers/html_renderer.py", line 183, in generate_document
    self.generate(element, context.extend(None, "body"))
  File "/home/harry/b2ai-standards-registry/.venv/lib/python3.9/site-packages/linkml_renderer/renderers/html_renderer.py", line 134, in generate
    return self.generate_object(element, context)
  File "/home/harry/b2ai-standards-registry/.venv/lib/python3.9/site-packages/linkml_renderer/renderers/html_renderer.py", line 235, in generate_object
    self.generate(v, context.extend(slot))
  File "/home/harry/b2ai-standards-registry/.venv/lib/python3.9/site-packages/linkml_renderer/renderers/html_renderer.py", line 119, in generate
    return self.elements_to_table(elements, context)
  File "/home/harry/b2ai-standards-registry/.venv/lib/python3.9/site-packages/linkml_renderer/renderers/html_renderer.py", line 300, in elements_to_table
    self.generate(v, context.extend(slot, "table"))
  File "/home/harry/b2ai-standards-registry/.venv/lib/python3.9/site-packages/linkml_renderer/renderers/html_renderer.py", line 107, in generate
    raise TypeError(f"Unexpected type for collection: {type(element)}")
TypeError: Unexpected type for collection: <class 'str'>

The same error is raised when attempting to render this data as markdown.
The schema and data are both valid as far as I can tell.

For comparison, this completes as expected:

$ linkml-render -s src/schema/standards_schema_all.yaml -r DataTopicContainer -t markdown -o test.md src/data/DataTopic.yaml 

This is with version 0.1.2.

@caufieldjh
Copy link
Author

Turns out this was an issue on my end: linkml-validate wasn't catching that some data in multivalued slots was provided as strings instead of lists. Rewriting the offending values as lists abolished this error.
Would be nice to know what the value of the unexpected type is in this case instead of just getting the whole stack trace, though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant