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

URL in sqlalchemy 1.4 is immutable causing AttributeError #816

Closed
justin-ellevation opened this issue Mar 23, 2021 · 5 comments
Closed

URL in sqlalchemy 1.4 is immutable causing AttributeError #816

justin-ellevation opened this issue Mar 23, 2021 · 5 comments
Labels

Comments

@justin-ellevation
Copy link

When using the latest alembic with the latest sqlalchemy migrations fail with an AttributeError: can't set attribute
I recently updated dependencies (alembic==1.5.7 and sqlalchemy==1.4.2). When running an alembic command in some environments, you get the following error: AttributeError: can't set attribute (full stack trace below). I believe (looking at the stacktrace below) that this is due to the fact that in sqlalchemy 1.4, they made the URL object immutable and the function that's causing the error (obfuscate_url_pw) is clearly trying to set an attribute on the returned (now immutable) object.

Expected behavior

Passwords are obfuscated but are done so in a way that plays well with the now-immutable URL object in sqlalchemy>=1.4.

To Reproduce

I've not been able to reproduce this outside of our CI/CD environment, even though we run it within the same docker container. I'll try to get some time to find the path that triggers the obfuscation of passwords based on the stack trace below, but here's our general setup:

  • pipenv to manage dependencies
  • alembic==1.5.7
  • sqlalchemy==1.4.2
  • SQL Server odbc driver (we use a custom pip package for this and custom docker layers, so I'll have to unwind those or see if I can repro with a simpler db-setup).

I was mostly trying the current alembic command, but it seems to be happening on other alembic commands as well.

Error

Traceback (most recent call last):
  File "/usr/local/bin/alembic", line 8, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.9/site-packages/alembic/config.py", line 559, in main
    CommandLine(prog=prog).main(argv=argv)
  File "/usr/local/lib/python3.9/site-packages/alembic/config.py", line 553, in main
    self.run_cmd(cfg, options)
  File "/usr/local/lib/python3.9/site-packages/alembic/config.py", line 530, in run_cmd
    fn(
  File "/usr/local/lib/python3.9/site-packages/alembic/command.py", line 506, in current
    script.run_env()
  File "/usr/local/lib/python3.9/site-packages/alembic/script/base.py", line 490, in run_env
    util.load_python_file(self.dir, "env.py")
  File "/usr/local/lib/python3.9/site-packages/alembic/util/pyfiles.py", line 97, in load_python_file
    module = load_module_py(module_id, path)
  File "/usr/local/lib/python3.9/site-packages/alembic/util/compat.py", line 182, in load_module_py
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 790, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "./env.py", line 58, in <module>
    run_migrations_online()
  File "./env.py", line 51, in run_migrations_online
    context.run_migrations()
  File "<string>", line 8, in run_migrations
  File "/usr/local/lib/python3.9/site-packages/alembic/runtime/environment.py", line 813, in run_migrations
    self.get_context().run_migrations(**kw)
  File "/usr/local/lib/python3.9/site-packages/alembic/runtime/migration.py", line 548, in run_migrations
    for step in self._migrations_fn(heads, self):
  File "/usr/local/lib/python3.9/site-packages/alembic/command.py", line 496, in display_version
    util.obfuscate_url_pw(context.connection.engine.url),
  File "/usr/local/lib/python3.9/site-packages/alembic/util/messaging.py", line 67, in obfuscate_url_pw
    u.password = "XXXXX"
AttributeError: can't set attribute

Versions.

  • OS: Docker image, base is python:3.9.0-slim-buster
  • Python: (3.9.0)
  • Alembic: 1.5.7
  • SQLAlchemy: 1.4.2
  • Database: SQL Server
  • DBAPI: pyodbc==4.0.28
@justin-ellevation justin-ellevation added the requires triage New issue that requires categorization label Mar 23, 2021
@sqla-tester
Copy link
Collaborator

Mike Bayer has proposed a fix for this issue in the master branch:

use new URL api for password obfuscate https://gerrit.sqlalchemy.org/c/sqlalchemy/alembic/+/2666

@zzzeek
Copy link
Member

zzzeek commented Mar 23, 2021

hi thanks for reporting this will be released today

@CaselIT CaselIT removed the requires triage New issue that requires categorization label Mar 23, 2021
@zzzeek
Copy link
Member

zzzeek commented Mar 23, 2021

1.5.8 is released

@justin-ellevation
Copy link
Author

Wow, thanks for the super fast turnaround on this!

@zzzeek
Copy link
Member

zzzeek commented Mar 23, 2021

it's a regression preventing people from using 1.4 so i take those seriously

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants