cli: Error with diff `'Session' object has no attribute 'engine'`

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

I’ve not being able to use supabase db diff --use-migra for some time now. Here’s my output:

❯ supabase db diff --use-migra
Connecting to local database...
Creating shadow database...
Applying migration 20230126132152_remote_commit.sql...
Applying migration 20230129165002_room_details.sql...
Applying migration 20230129165313_bill.sql...
Applying migration 20230209135221_foreign_key_refactor.sql...
Applying migration 20230211221504_departure_description.sql...
Applying migration 20230211222015_departure_time.sql...
Applying migration 20230211224341_departure_day.sql...
Applying migration 20230211224908_departure_stop.sql...
Applying migration 20230211225343_arrival_stop.sql...
Applying migration 20230211225944_bus_capacity.sql...
Applying migration 20230211230437_admin_id.sql...
Applying migration 20230211230712_created_at.sql...
Applying migration 20230211232100_discounts_table_rename.sql...
Applying migration 20230211234820_trips_table_rename.sql...
Applying migration 20230212030923_reservations_table_snake_case.sql...
Applying migration 20230213015544_departure_day_number.sql...
Applying migration 20230214120043_settings_table.sql...
Applying migration 20230216044935_everything_is_nullable.sql...
Applying migration 20230216112215_repeating_trips_admin.sql...
Applying migration 20230216142213_function_snake_case.sql...
Applying migration 20230217053323_settings_updated_by.sql...
Applying migration 20230218100222_generated_updated_default.sql...
Applying migration 20230219042902_reservations_table_metadata.sql...
Applying migration 20230223095950_remote_commit.sql...
Applying migration 20230226100648_db_trigger_before_delete.sql...
Applying migration 20230226101002_deleted_db_trigger_after_delete.sql...
Applying migration 20230306192629_reservations_nationality.sql...
Diffing schemas: auth,extensions,public,storage
Error: error diffing schema: error running container: exit 1:
WARNING: Running pip as root will break packages and permissions. You should install packages reliably by using venv: https://pip.pypa.io/warnings/venv
WARNING: You are using pip version 21.1.1; however, version 23.0.1 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/schemainspect/misc.py", line 9, in connection_from_s_or_c
    s_or_c.engine
AttributeError: 'Session' object has no attribute 'engine'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 3212, in _wrap_pool_connect
    return fn()
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 301, in connect
    return _ConnectionFairy._checkout(self)
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 761, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 419, in checkout
    rec = pool._do_get()
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/impl.py", line 145, in _do_get
    self._dec_overflow()
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/impl.py", line 142, in _do_get
    return self._create_connection()
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 247, in _create_connection
    return _ConnectionRecord(self)
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 362, in __init__
    self.__connect()
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 605, in __connect
    pool.logger.debug("Error on connect(): %s", e)
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 599, in __connect
    connection = pool._invoke_creator(self)
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/create.py", line 578, in connect
    return dialect.connect(*cargs, **cparams)
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 584, in connect
    return self.dbapi.connect(*cargs, **cparams)
  File "/usr/local/lib/python3.9/site-packages/psycopg2/__init__.py", line 127, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: could not translate host name "localhost" to address: Name does not resolve


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/bin/migra", line 8, in <module>
    sys.exit(do_command())
  File "/usr/local/lib/python3.9/site-packages/migra/command.py", line 121, in do_command
    status = run(args)
  File "/usr/local/lib/python3.9/site-packages/migra/command.py", line 86, in run
    m = Migration(
  File "/usr/local/lib/python3.9/site-packages/migra/migra.py", line 31, in __init__
    self.changes.i_from = get_inspector(
  File "/usr/local/lib/python3.9/site-packages/schemainspect/get.py", line 14, in get_inspector
    c = connection_from_s_or_c(x)
  File "/usr/local/lib/python3.9/site-packages/schemainspect/misc.py", line 14, in connection_from_s_or_c
    return s_or_c.connection()
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 1516, in connection
    return self._connection_for_bind(
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 1526, in _connection_for_bind
    return self._transaction._connection_for_bind(
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 747, in _connection_for_bind
    conn = bind.connect()
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 3166, in connect
    return self._connection_cls(self, close_with_result=close_with_result)
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 96, in __init__
    else engine.raw_connection()
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 3245, in raw_connection
    return self._wrap_pool_connect(self.pool.connect, _connection)
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 3215, in _wrap_pool_connect
    Connection._handle_dbapi_exception_noconnection(
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 2068, in _handle_dbapi_exception_noconnection
    util.raise_(
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/base.py", line 3212, in _wrap_pool_connect
    return fn()
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 301, in connect
    return _ConnectionFairy._checkout(self)
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 761, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 419, in checkout
    rec = pool._do_get()
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/impl.py", line 145, in _do_get
    self._dec_overflow()
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/impl.py", line 142, in _do_get
    return self._create_connection()
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 247, in _create_connection
    return _ConnectionRecord(self)
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 362, in __init__
    self.__connect()
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 605, in __connect
    pool.logger.debug("Error on connect(): %s", e)
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/langhelpers.py", line 70, in __exit__
    compat.raise_(
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/pool/base.py", line 599, in __connect
    connection = pool._invoke_creator(self)
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/create.py", line 578, in connect
    return dialect.connect(*cargs, **cparams)
  File "/usr/local/lib/python3.9/site-packages/sqlalchemy/engine/default.py", line 584, in connect
    return self.dbapi.connect(*cargs, **cparams)
  File "/usr/local/lib/python3.9/site-packages/psycopg2/__init__.py", line 127, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not translate host name "localhost" to address: Name does not resolve

(Background on this error at: http://sqlalche.me/e/14/e3q8)

Try rerunning the command with --debug to troubleshoot the error.

To Reproduce

  1. Run supabase db diff --use-migra
  2. See the error

Expected behavior

Should output the diff.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: Arch linux
  • cli: 1.45.0
  • Docker: 23.0.1

Additional context

I stopped all containers, removed them, deleted all docker images, disabled ufw, rebooted my PC, removed supabase cli, started all over again with supabase start it downloaded images, setup everything… but the issue still here.

Please note that the API, database and everything works normally, but not the diff tool.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 17 (4 by maintainers)

Most upvoted comments

Found a way to recreate this.

If I am connected to my WiFi this is throwing the above error. but when I connect to the hotspot on my phone this thing works. Also on WiFi it used to work before but threw a error Retrying... db.ffvylgetjuuiwexvgjfm.supabase.co 5432 . Probably has to do something with connections.