question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

KeyError: '_data'

See original GitHub issue

With

  • Python 3.9.2
  • sqlalchemy 1.4.0

I get this error:

Traceback (most recent call last):
  File "/home/julian/src/bruce-leads/.venv/lib/python3.9/site-packages/sqlalchemy/sql/base.py", line 1104, in __getattr__
    return self._index[key]
KeyError: '_data'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/julian/src/bruce-leads/.venv/bin/eralchemy", line 8, in <module>
    sys.exit(cli())
  File "/home/julian/src/bruce-leads/.venv/lib/python3.9/site-packages/eralchemy/main.py", line 31, in cli
    render_er(
  File "/home/julian/src/bruce-leads/.venv/lib/python3.9/site-packages/eralchemy/main.py", line 231, in render_er
    tables, relationships = all_to_intermediary(input, schema=schema)
  File "/home/julian/src/bruce-leads/.venv/lib/python3.9/site-packages/eralchemy/main.py", line 147, in all_to_intermediary
    return database_to_intermediary(filename_or_input, schema=schema)
  File "/home/julian/src/bruce-leads/.venv/lib/python3.9/site-packages/eralchemy/sqla.py", line 82, in database_to_intermediary
    return declarative_to_intermediary(Base)
  File "/home/julian/src/bruce-leads/.venv/lib/python3.9/site-packages/eralchemy/sqla.py", line 61, in declarative_to_intermediary
    return metadata_to_intermediary(base.metadata)
  File "/home/julian/src/bruce-leads/.venv/lib/python3.9/site-packages/eralchemy/sqla.py", line 54, in metadata_to_intermediary
    tables = [table_to_intermediary(table) for table in metadata.tables.values()]
  File "/home/julian/src/bruce-leads/.venv/lib/python3.9/site-packages/eralchemy/sqla.py", line 54, in <listcomp>
    tables = [table_to_intermediary(table) for table in metadata.tables.values()]
  File "/home/julian/src/bruce-leads/.venv/lib/python3.9/site-packages/eralchemy/sqla.py", line 49, in table_to_intermediary
    return Table(name=table.fullname, columns=[column_to_intermediary(col) for col in table.c._data.values()])
  File "/home/julian/src/bruce-leads/.venv/lib/python3.9/site-packages/sqlalchemy/sql/base.py", line 1106, in __getattr__
    util.raise_(AttributeError(key), replace_context=err)
  File "/home/julian/src/bruce-leads/.venv/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 180, in raise_
    raise exception
AttributeError: _data

I have investigated to fix it for sqlachemy but don’t know about backwards compat.

https://github.com/Alexis-benoist/eralchemy/blob/d6fcdc67d6d413bb174bf008fd360044e1dff5a7/eralchemy/sqla.py#L50

needs to be replaced with:

columns=[column_to_intermediary(col) for col in table.c._colset]

I can create a tested PR if you are willing to merge it.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:46
  • Comments:10

github_iconTop GitHub Comments

6reactions
tonycommented, Jun 15, 2021

Another workaround, if you don’t need 1.4 (release notes on docs.sqlalchemy.org), pinning sqlalchemy<1.4 would fix this. To test: pip install 'sqlalchemy<1.4'

5reactions
smitty1eGHcommented, Feb 19, 2022

columns=[column_to_intermediary(col) for col in table.c._colset] is still needful with

  • Python 3.10.2
  • SQLAlchemy 1.4.31
Read more comments on GitHub >

github_iconTop Results From Across the Web

Python 2.7.6, KeyError: 'data' when trying to run script
KeyError means that there is no such key in a dict object. Therefore it means your file does not contain JSON data structure...
Read more >
Python KeyError Exceptions and How to Handle Them
Python's official documentation says that the KeyError is raised when a mapping key is accessed and isn't found in the mapping. A mapping...
Read more >
What is KeyError in Python? Dictionary and Handling Them
The mapping logic is a data structure that maps one set of data to significant others. Hence, it is an error, which is...
Read more >
KeyError Pandas – How To Fix - Data Independent
Pandas KeyError - This annoying error means that Pandas can not find your column name in your dataframe. Here's how to fix this...
Read more >
KeyError: 'data' - Academic Research - Twitter Developers
KeyError : 'data' ... I tried to collect all the tweets matching my requirement within one month. In the begining the code works...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found