pudo / dataset

Easy-to-use data handling for SQL data stores with support for implicit table creation, bulk loading, and transactions.
https://dataset.readthedocs.org/
MIT License
4.76k stars 297 forks source link

`_mapping` throws exception for find query in SQLite #389

Closed promethean closed 2 years ago

promethean commented 2 years ago

Looks a great library but hit a hurdle at the first attempt.

As per the v. basic Quickstart example here: https://dataset.readthedocs.io/en/latest/index.html

for user in db['user']:
   print(user['age'])

Throws an error:

AttributeError: Could not locate column in row for column '_mapping'

Referring to line: https://github.com/pudo/dataset/blob/8c91b6feaaeb92838ae8f2cee00ab71012d1c11f/dataset/util.py#L17

It returns the correct results if changed to return row.items() instead of row._mapping.items()

yadalik commented 2 years ago

Also got this after updating dataset to latest 1.5.1 on previously worked code, changing row._mapping.items() to row.items() helped, but then I reverted it back and tried just to update sqlalchemy to latest and error disappeared (sqlalchemy during update also cried about some incompatible version of marshmallow, so updated it too, not sure this important, just in case).

    if d := tt['text_merged_base'].find_one(image=image):
  File "...\lib\site-packages\dataset\table.py", line 649, in find_one
    for row in resiter:
  File "...\lib\site-packages\dataset\util.py", line 87, in __next__
    return convert_row(self.row_type, next(self._iter))
  File "...\lib\site-packages\dataset\util.py", line 17, in convert_row
    return row_type(row._mapping.items())
AttributeError: Could not locate column in row for column '_mapping'

P.S.: maybe some versions of supported libs should be changed, maybe this will help (yet I did not update things before in a long time, so maybe ranges of those libs could be expanded): sqlalchamy updated from 1.3.19 to latest (current 1.4.28)

ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
marshmallow-sqlalchemy 0.24.0 requires marshmallow>=3.0.0, but you have marshmallow 2.21.0 which is incompatible.

so marshmallow updated from 2.21.0 to latest (current 3.14.1)

ohld commented 2 years ago

Just received the same issue. Happened when updated to 1.5.1. @pudo

pudo commented 2 years ago

Yep it looks like SQLAlchemy 1.4 has introduced a new result type: https://docs.sqlalchemy.org/en/14/core/connections.html#sqlalchemy.engine.Result - I'm kind of tempted to start tagging the versions of SQLAlchemy that dataset will work with... Going to try and work out a fix now.

pudo commented 2 years ago

Ok, so it looks like row._mapping doesn't exist in sqlalchemy 1.3, exists in 1.4 and will be the default in 2.0. I've added some crappy ImportError work-around now that should ensure it works with both 1.3 and 1.4.

ohld commented 2 years ago

@pudo thanks for quick help! Will you bump the updated version in pip?

pudo commented 2 years ago

should be available now :)