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

Alembic raising an error when creating the migration script for a postgreSQL DB #3

Open
afcristia opened this issue May 7, 2024 · 6 comments
Labels
question Further information is requested

Comments

@afcristia
Copy link

I am working through the book (Kindle version) and got stuck when introducing Alembic as the create migration command raises an error as follows:

File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/configparser.py", line 374, in before_set
raise ValueError("invalid interpolation syntax in %r at "
ValueError: invalid interpolation syntax in 'postgresql+psycopg2://retrofun:123.%[email protected]:5432/retrofun' at position 35

I'm running a postgreSQL database on another computer on my local network. I tried copying the line used for SQLAlchemy to connect with no luck.

I know I could be missing something but I could find a suitable solution when googling for a solution, hence the need to reach out to you.

I am adding the env.py (as a .txt file as GitHub doesn't allow .py files)

env.txt

@miguelgrinberg
Copy link
Owner

@afcristia The "%" that you have in your password is causing this, because this character is used for interpolation. Use "%%" to escape it.

@miguelgrinberg miguelgrinberg added the question Further information is requested label May 7, 2024
@afcristia
Copy link
Author

thanks for your prompt reply. However, I'am affraid that's not it, as my password doesn't have a % sign.
env.txt

I'm attaching my .env file (with a .txt extension) so you can check. Alembic is changing ".," in my password for ".%2C" somewhere with its code, but I have no idea where it could be.

@miguelgrinberg
Copy link
Owner

To determine where is this happening it would be useful to see the complete stack trace of the error.

@afcristia
Copy link
Author

error.txt

I'm now attaching the whole output. Thanks again for your support.

@miguelgrinberg
Copy link
Owner

In env.py, change this line:

config.set_main_option("sqlalchemy.url", engine.url.render_as_string(
    hide_password=False))

to this:

config.set_main_option("sqlalchemy.url", engine.url.render_as_string(
    hide_password=False).replace('%', '%%'))

Let me know if that helps!

@afcristia
Copy link
Author

I just tried it and worked perfectly.
retrofun - public

Thanks so much.

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

No branches or pull requests

2 participants