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

Formatted str should not be treated as Iterable #203

Closed
2 tasks done
okapies opened this issue Jun 22, 2022 · 0 comments · Fixed by #204
Closed
2 tasks done

Formatted str should not be treated as Iterable #203

okapies opened this issue Jun 22, 2022 · 0 comments · Fixed by #204

Comments

@okapies
Copy link
Contributor

okapies commented Jun 22, 2022

Checklist

  • The bug is reproducible against the latest release or master.
  • There are no similar issues or pull requests to fix it yet.

Describe the bug

As of 0.1.10, the templates use the new is_iterable function instead of is_list (#174). But now some list and details admin pages that have custom column_formatters or column_formatters_detail produce Internal Server Error.

It is because str object returned from the formatter is determined as Iterable and the formatted value is passed to _url_for_details(). It is a variation of #196.

>>> from collections.abc import Iterable
>>> isinstance("foo", Iterable)
True

Steps to reproduce the bug

No response

Expected behavior

No response

Actual behavior

No response

Debugging material

  File "/myproject/.venv/lib/python3.9/site-packages/sqladmin/templates/list.html", line 113, in block 'content'
    <a href="{{ model_admin._url_for_details(value) }}">({{ value }})</a>
  File "/myproject/.venv/lib/python3.9/site-packages/sqladmin/models.py", line 609, in _url_for_details
    pk = getattr(obj, inspect(obj).mapper.primary_key[0].name)
  File "/myproject/.venv/lib/python3.9/site-packages/sqlalchemy/inspection.py", line 71, in inspect
    raise exc.NoInspectionAvailable(
sqlalchemy.exc.NoInspectionAvailable: No inspection system is available for object of type <class 'str'>

Environment

  • Ubuntu 20.04.4 LTS
  • Python 3.9.12
  • SQLAdmin 0.1.9

Additional context

No response

@okapies okapies changed the title str is not Iterable Formatted str should not be treated as Iterable Jun 22, 2022
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

Successfully merging a pull request may close this issue.

1 participant