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

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

Open
jmckenna opened this issue Sep 10, 2024 · 2 comments

Comments

@jmckenna
Copy link
Member

jmckenna commented Sep 10, 2024

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 #720 )

cc @tchaddad

@jmckenna
Copy link
Member Author

jmckenna commented Sep 10, 2024

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.

@jmckenna
Copy link
Member Author

Closing (packagers can/will find this closed ticket with the workaround).

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

No branches or pull requests

1 participant