0

I want to ask why my create_engine error? my port was right, I tried it on my local, and it has nothing error from here. But, when I deployed it on my GCP, it got an error like this. My SQLAlchemy version on my local with GCP has the same version.


Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
    worker.init_process()
  File "/usr/local/lib/python3.8/site-packages/uvicorn/workers.py", line 57, in init_process
    super(UvicornWorker, self).init_process()
  File "/usr/local/lib/python3.8/site-packages/gunicorn/workers/base.py", line 119, in init_process
    self.load_wsgi()
  File "/usr/local/lib/python3.8/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python3.8/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/usr/local/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
    return self.load_wsgiapp()
  File "/usr/local/lib/python3.8/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/usr/local/lib/python3.8/site-packages/gunicorn/util.py", line 358, in import_app
    mod = importlib.import_module(module)
  File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/app/main.py", line 20, in <module>
    from db.session_car import SessionLocal as SessionLocalCar
  File "/app/db/session_car.py", line 5, in <module>
    engine = create_engine(settings.DATABASE_URL_CAR, pool_pre_ping=True)
  File "<string>", line 2, in create_engine
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/util/deprecations.py", line 298, in warned 

Does anyone has got the same error me?

EDITED: Found the solution, downgrade the SQLAlchemy version. sqlalchemy_utils is currently not compatible with SQLAlchemy > 1.4.0

SQLAlchemy-utils not compatible with SQLAlchemy > 1.4.0

MADFROST
  • 1,043
  • 2
  • 11
  • 29
  • are there any more lines after that? – jabbson Mar 24 '21 at 03:40
  • @jabbson Okay, i found the solution, SQLAlchemy-utils not working again on SQLAlchemy after SQLAlchemy updated version to > 1.4 – MADFROST Mar 24 '21 at 03:44
  • Does this answer your question? [SQLalchemy making errors after being updated to 1.4.0](https://stackoverflow.com/questions/66651661/sqlalchemy-making-errors-after-being-updated-to-1-4-0) – rfkortekaas Mar 24 '21 at 07:35
  • 1
    @rfkortekaas Thank you for the answer, yeah that is the solution. So I downgrade my SQLAlcemy – MADFROST Mar 25 '21 at 12:44
  • @RudyTriSaputra Could you post the solution you found as an answer? I would be helpful for the community as per users having similar problems. – Nahuel Apr 13 '21 at 12:26

2 Answers2

1

As @RudyTriSaputra said in the comment section, SQLAlchemy-utils does not work on SQLAlchemy after being updated to 1.4.0 or higher. Therefore, the solution is downgrade its version.

Nahuel
  • 158
  • 8
0

I also had this error:

File "<string>", line 2, in create_engine: File "/layers/google.python.pip/pip/lib/python3.9/site-packages/sqlalchemy/util/deprecations.py", line 309, in warned

Downgrading sqlalchemy is not needed, you can well take the latest version, and perhaps that will already take the error away. I cannot test this again, there were too many steps in between.

What could have made it:

  • As said above, add SQLAlchemy>=1.4.2 to the "requirements.txt".
  • Also add "mysqlclient==2.1.0" package to the requirements.txt, and in the "main.py", add the driver keyword "+mysqldb", see the link. There are also other driver possible, but this mysqlclient is said to be the fastest.
  • I also needed a VPC connector to reach out to my local non-Google-Cloud mysql server, see How to access a non-Google MySQL server database (no Cloud SQL!) from Google Cloud Function in Python runtime using SQLAlchemy. Perhaps that was the issue here. That would fit to what you write that you could reach it locally but not from the GCF. You can only find Cloud SQL databases, for others you need a VPC connector which costs a tiny fee, nothing big.
questionto42
  • 7,175
  • 4
  • 57
  • 90