geopython / pycsw

pycsw is an OGC CSW server implementation written in Python. pycsw fully implements the OpenGIS Catalogue Service Implementation Specification [Catalogue Service for the Web]. Initial development started in 2010 (more formally announced in 2011). The project is certified OGC Compliant, and is an OGC Reference Implementation. pycsw allows for the publishing and discovery of geospatial metadata via numerous APIs (CSW 2/CSW 3, OpenSearch, OAI-PMH, SRU). Existing repositories of geospatial metadata can also be exposed, providing a standards-based metadata and catalogue component of spatial data infrastructures. pycsw is Open Source, released under an MIT license, and runs on all major platforms (Windows, Linux, Mac OS X). Please read the docs at https://pycsw.org/docs for more information.
https://pycsw.org
MIT License
203 stars 155 forks source link

sqlite3 connection on Windows: TypeError: declarative_base() got an unexpected keyword argument 'bind' #1012

Open jmckenna opened 1 week ago

jmckenna commented 1 week ago

Description

A previous pycsw build on Windows, pycsw-2.6.0, had no problems connecting to an SQLite3 repo, such as:

database=sqlite:///C:\\ms4w\\apps\\pycsw-2.6.0\\tests\\functionaltests\\suites\\cite\\data\\cite.db

However with master (and obviously many updated libs underneath), with the same connection in the .yml file:

database: 'sqlite:///C:\\ms4w\\apps\\pycsw-git-master\\tests\\functionaltests\\suites\\cite\\data\\cite.db'

caused error of Could not initialize repository. Check server logs and more specifically: TypeError: declarative_base() got an unexpected keyword argument 'bind'

Traceback

[2024-09-10T09:53:47Z] {C:\ms4w\Python\Lib\site-packages\pycsw\core\repository.py:72} INFO - creating new engine: sqlite:///C:\\ms4w\\apps\\pycsw-git-master\\tests\\functionaltests\\suites\\cite\\data\\cite.db
[2024-09-10T09:53:47Z] {C:\ms4w\Python\Lib\site-packages\pycsw\server.py:430} ERROR - Could not load repository (local): cannot access local variable 'err' where it is not associated with a value
Traceback (most recent call last):
  File "C:\ms4w\Python\Lib\site-packages\pycsw\server.py", line 415, in dispatch
    self.repository = repository.Repository(
                      ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\ms4w\Python\Lib\site-packages\pycsw\core\repository.py", line 106, in __init__
    base = declarative_base(bind=self.engine)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 2, in declarative_base
  File "C:\ms4w\Python\Lib\site-packages\sqlalchemy\util\deprecations.py", line 386, in warned
    return fn(*args, **kwargs)  # type: ignore[no-any-return]
           ^^^^^^^^^^^^^^^^^^^
  File "C:\ms4w\Python\Lib\site-packages\sqlalchemy\ext\declarative\__init__.py", line 27, in declarative_base
    return _declarative_base(*arg, **kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: declarative_base() got an unexpected keyword argument 'bind'

Workaround

I noticed that the SQLAlchemy 2.0 release had some changes in regards to declarative_base(), so I uninstalled SQLAlchemy 2.0.34, and installed 1.4.54, and the problem went away.

Environment

( tackled during my battles with https://github.com/geopython/pycsw/issues/720 )

cc @tchaddad

jmckenna commented 1 week ago

I forgot to mention, that I confirmed outside of pycsw that SQLAlchemy is able to connect to sqlite3 through sqlalchemy.create_engine(), with SQLAlchemy 2.0.34 using sqlalchemy.inspect(), with the same path, so then I looked deeper into pycsw's repository.py and noticed the declarative_base() error.