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

KeyError: '_data' #80

Open
julian-r opened this issue Mar 19, 2021 · 12 comments · May be fixed by sturzaam/eralchemy#1
Open

KeyError: '_data' #80

julian-r opened this issue Mar 19, 2021 · 12 comments · May be fixed by sturzaam/eralchemy#1

Comments

@julian-r
Copy link

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.

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

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.

@emilheunecke
Copy link

Worked for me too

@andrescevp
Copy link

andrescevp commented Mar 27, 2021

up

also happens in python 3.8 and ERAlchemy==1.2.10/ SQLAlchemy==1.4.3

@LuisPeregrinaIBM2
Copy link

Hitting same issue, same versions mentioned.

sturzaam added a commit to sturzaam/eralchemy that referenced this issue Apr 5, 2021
@sturzaam sturzaam linked a pull request Apr 5, 2021 that will close this issue
@lulou
Copy link

lulou commented Apr 11, 2021

Same issue for me. The change fixed the problem for me.

@RyanCPeters
Copy link

RyanCPeters commented May 25, 2021

A possible fix that should allow for backwards compatibility is to use the builtin getattr(...) function in the list comprehension.

something like this is working for me:

def table_to_intermediary(table):
    """Transform an SQLAlchemy Table object to it's intermediary representation. """
    return Table(
        name=table.fullname,
        # columns=[column_to_intermediary(col) for col in table.c._data.values()]
        # columns=[column_to_intermediary(col) for col in (table.c._data.values() if hasattr(table.c,"_data") else table.c._colset)]
        columns=[column_to_intermediary(col) for col in getattr(table.c,"_colset",getattr(table.c,"_data",{}).values())]
    )

EDIT:
forgot the python syntax tag, and while I was here I included commented lines with the original implementation and a slightly more verbose alternative implementation.

@tony
Copy link

tony commented 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'

tony added a commit to cihai/cihai that referenced this issue Jun 15, 2021
@ISipi
Copy link

ISipi commented Jun 29, 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'

This worked for me. Thanks!

pgold pushed a commit to pgold/eralchemy that referenced this issue Aug 14, 2021
eveith added a commit to eveith/eralchemy that referenced this issue Oct 6, 2021
@lukasmu lukasmu mentioned this issue Nov 16, 2021
benjamin-kirkbride added a commit to benjamin-kirkbride/eralchemy that referenced this issue Jan 8, 2022
@smitty1eGH
Copy link

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

  • Python 3.10.2
  • SQLAlchemy 1.4.31

@maurerle
Copy link

I added a fork of eralchemy in this repo which contains fixes for the current SQLAlchemy version: #94
https://github.com/maurerle/eralchemy2

darlannakamura added a commit to darlannakamura/eralchemy2 that referenced this issue Jul 5, 2022
@vinimlo
Copy link

vinimlo commented Sep 30, 2022

Fix works for me!

darlannakamura added a commit to darlannakamura/eralchemy2 that referenced this issue Oct 19, 2022
@tarunsengar1987
Copy link

i am getting this same issue
python 3.10.6
sqlalchemy 2.0.16

@maurerle
Copy link

Hi @tarunsengar1987 ,
you can use "pip install eralchemy2" instead which has fixes for issues like this:
https://github.com/maurerle/eralchemy2

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.