eralchemy icon indicating copy to clipboard operation
eralchemy copied to clipboard

Cryptic ArgumentError lets ERAlchemy fail to load sqlite db

Open Anaphory opened this issue 6 years ago • 4 comments

Some time ago, I managed to generate a nice ER diagram from a previous version of my database. Howerver today, running eralchemy on my sqlite database

$ file lexirumah.sqlite
lexirumah.sqlite: SQLite 3.x database

now fails with a value error which does not make obvious what the problem is. I have checked with the current version of eralchemy from pip, with the most recent checkout of the master branch and with tag v1.0.15, and in all cases I get

$ eralchemy -i "sqlite://lexirumah.sqlite" -o erd_from_sqlite.svg
Traceback (most recent call last):
  File "/vol/home/kaipingga/.local/bin/eralchemy", line 11, in <module>
    load_entry_point('ERAlchemy', 'console_scripts', 'eralchemy')()
  File "/vol/home/kaipingga/devel/eralchemy/eralchemy/main.py", line 33, in cli
    render_er(args.i, args.o, exclude=args.x, schema=args.s)
  File "/vol/home/kaipingga/devel/eralchemy/eralchemy/main.py", line 179, in render_er
    tables, relationships = all_to_intermediary(input, schema=schema)
  File "/vol/home/kaipingga/devel/eralchemy/eralchemy/main.py", line 130, in all_to_intermediary
    raise ValueError(msg)
ValueError: Cannot process filename_or_input str

Running pdb on the problem shows that the problem is that database_to_intermediary finds some problem somewhere in my DB and fails with an ArgumentError, which leads the calling function to assume that it got passed something that was not a DB URI as filename_or_input (which in this case is the wrong conclusion).

(Pdb) database_to_intermediary(filename_or_input, schema=None)
*** sqlalchemy.exc.ArgumentError: WARNING: when configuring property 'value' on Mapper|value_data|value_data, column 'value' conflicts with property '<RelationshipProperty at 0x7fb3554abd48; value>'. To resolve this, map the column to the class under a different name in the 'properties' dictionary.  Or, to remove all awareness of the column entirely (including its availability as a foreign key), use the 'include_properties' or 'exclude_properties' mapper arguments to control specifically which table columns get mapped.

I have no idea what this means. I have attached the output of sqlite3 lexirumah.sqlite .dump | grep -v INSERT, in case looking at the table schema helps finding the issue. db_schema.txt

Anaphory avatar Feb 05 '18 12:02 Anaphory

The complete traceback below database_to_intermediary is as follows.

  File "/vol/home/kaipingga/devel/eralchemy/eralchemy/sqla.py", line 77, in database_to_intermediary
    Base.prepare(engine, reflect=True)
  File "/vol/home/kaipingga/.local/lib/python3.5/site-packages/sqlalchemy/ext/automap.py", line 799, in prepare
    map_config.map()
  File "/vol/home/kaipingga/.local/lib/python3.5/site-packages/sqlalchemy/ext/declarative/base.py", line 643, in map
    return super(_DeferredMapperConfig, self).map()
  File "/vol/home/kaipingga/.local/lib/python3.5/site-packages/sqlalchemy/ext/declarative/base.py", line 576, in map
    **self.mapper_args
  File "<string>", line 2, in mapper
  File "/vol/home/kaipingga/.local/lib/python3.5/site-packages/sqlalchemy/orm/mapper.py", line 692, in __init__
    self._configure_properties()
  File "/vol/home/kaipingga/.local/lib/python3.5/site-packages/sqlalchemy/orm/mapper.py", line 1417, in _configure_properties
    setparent=True)
  File "/vol/home/kaipingga/.local/lib/python3.5/site-packages/sqlalchemy/orm/mapper.py", line 1621, in _configure_property
    prop = self._property_from_column(key, prop)
  File "/vol/home/kaipingga/.local/lib/python3.5/site-packages/sqlalchemy/orm/mapper.py", line 1794, in _property_from_column
    (key, self, column.key, prop))
sqlalchemy.exc.ArgumentError: WARNING: when configuring property 'value' on Mapper|value_data|value_data, column 'value' conflicts with property '<RelationshipProperty at 0x7f0d3c0edbc8; value>'. To resolve this, map the column to the class under a different name in the 'properties' dictionary.  Or, to remove all awareness of the column entirely (including its availability as a foreign key), use the 'include_properties' or 'exclude_properties' mapper arguments to control specifically which table columns get mapped.

Anaphory avatar Feb 05 '18 13:02 Anaphory

Hi @Anaphory,

Did you find a workaround? I am facing the same issue.

I figured out the trigger of this error: ALTER TABLE IF EXISTS "movement" ADD CONSTRAINT FK_MOVEMENT_STATUS FOREIGN KEY(physical_status) REFERENCES "physical_status"(id);

I tried to rewrite this constraint with a different name without success.

If I remove it, the error disappear.

jhayotte avatar May 29 '18 12:05 jhayotte

I assume you have to add a third / to your command like this:

eralchemy -i "sqlite:///lexirumah.sqlite" -o erd_from_sqlite.svg

luerhard avatar Sep 16 '20 09:09 luerhard

Wow, yes! That looks like a very correct assessment of the problem. Can that be caught and the user be given a hint?

Anaphory avatar Sep 16 '20 10:09 Anaphory