sqlite3 connection on Windows: TypeError: declarative_base() got an unexpected keyword argument 'bind'
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
- operating system: Windows
- Python version: 3.12.5
- pycsw version: today's master, built from source
- web server
- testing with CGI, and mod_wsgi (both successful, after workaround here) through Apache
( tackled during my battles with https://github.com/geopython/pycsw/issues/720 )
cc @tchaddad
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.
Closing (packagers can/will find this closed ticket with the workaround).
This Issue has been inactive for 90 days. In order to manage maintenance burden, it will be automatically closed in 7 days.
This Issue has been closed due to there being no activity for more than 90 days.