fief-dev / fief

Users and authentication management SaaS
https://www.fief.dev
Other
486 stars 42 forks source link

fief_tenants does not exist sqlalchemy.dialects.postgresql.asyncpg.ProgrammingError #270

Closed JustinGuese closed 9 months ago

JustinGuese commented 9 months ago

Describe the bug

when setting up the self hosted POSTGRESQL, the application enters a permanent loop crashing the the "fief_tenants" tables does not exist SqlAlchemy error

To Reproduce

Steps to reproduce the behavior:

  1. Set up Selfhosted like described in https://docs.fief.dev/self-hosting/quickstart/
  2. Add the postgresql data as described in https://docs.fief.dev/self-hosting/deployment/setup-database/
  3. create that user, database, password in postgresql
  4. run the app
  5. endless crash loop

Expected behavior

no crash

Configuration

Additional context

running in docker swarm, psql 14

│ /usr/local/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/async │
│ pg.py:802 in _handle_exception                                               │
│                                                                              │
│    799 │   │   │   │   │   translated_error.pgcode = (                       │
│    800 │   │   │   │   │   │   translated_error.sqlstate                     │
│    801 │   │   │   │   │   ) = getattr(error, "sqlstate", None)              │
│ ❱  802 │   │   │   │   │   raise translated_error from error                 │
│    803 │   │   │   else:                                                     │
│    804 │   │   │   │   raise error                                           │
│    805 │   │   else:                                                         │
│                                                                              │
│ ╭───────────────────────────────── locals ─────────────────────────────────╮ │
│ │             error = UndefinedTableError('relation                        │ │
│ │                     "f1e68fa1-e1fd-4306-8f98-33f981afc8b5.fief_tenants"  │ │
│ │                     does not exist')                                     │ │
│ │ exception_mapping = {                                                    │ │
│ │                     │   <class                                           │ │
│ │                     'asyncpg.exceptions.IntegrityConstraintViolationErr… │ │
│ │                     <class                                               │ │
│ │                     'sqlalchemy.dialects.postgresql.asyncpg.AsyncAdapt_… │ │
│ │                     │   <class                                           │ │
│ │                     'asyncpg.exceptions._base.PostgresError'>: <class    │ │
│ │                     'sqlalchemy.dialects.postgresql.asyncpg.AsyncAdapt_… │ │
│ │                     │   <class                                           │ │
│ │                     'asyncpg.exceptions.SyntaxOrAccessError'>: <class    │ │
│ │                     'sqlalchemy.dialects.postgresql.asyncpg.AsyncAdapt_… │ │
│ │                     │   <class                                           │ │
│ │                     'asyncpg.exceptions._base.InterfaceError'>: <class   │ │
│ │                     'sqlalchemy.dialects.postgresql.asyncpg.AsyncAdapt_… │ │
│ │                     │   <class                                           │ │
│ │                     'asyncpg.exceptions.InvalidCachedStatementError'>:   │ │
│ │                     <class                                               │ │
│ │                     'sqlalchemy.dialects.postgresql.asyncpg.AsyncAdapt_… │ │
│ │                     │   <class                                           │ │
│ │                     'asyncpg.exceptions.InternalServerError'>: <class    │ │
│ │                     'sqlalchemy.dialects.postgresql.asyncpg.AsyncAdapt_… │ │
│ │                     }                                                    │ │
│ │              self = <AdaptedConnection <asyncpg.connection.Connection    │ │
│ │                     object at 0xffff97550040>>                           │ │
│ │            super_ = <class 'asyncpg.exceptions.SyntaxOrAccessError'>     │ │
│ │  translated_error = ProgrammingError('<class                             │ │
│ │                     \'asyncpg.exceptions.UndefinedTableError\'>:         │ │
│ │                     relation                                             │ │
│ │                     "f1e68fa1-e1fd-4306-8f98-33f981afc8b5.fief_tenants"  │ │
│ │                     does not exist')                                     │ │
│ ╰──────────────────────────────────────────────────────────────────────────╯ │
╰──────────────────────────────────────────────────────────────────────────────╯
ProgrammingError: (sqlalchemy.dialects.postgresql.asyncpg.ProgrammingError) 
<class 'asyncpg.exceptions.UndefinedTableError'>: relation 
"f1e68fa1-e1fd-4306-8f98-33f981afc8b5.fief_tenants" does not exist
JustinGuese commented 9 months ago

are we limited to a specific PSQL version?

frankie567 commented 9 months ago

In your database, can you confirm the schema f1e68fa1-e1fd-4306-8f98-33f981afc8b5 was created and contains fief_* tables?

JustinGuese commented 9 months ago

hi @frankie567 thanks for the quick reply! No it was not:

image
frankie567 commented 9 months ago

So, this is the public schema. In PostgreSQL, you can have "schemas" which are like "sub-databases" inside a database. Depending on your client, you'll have different ways of accessing it.

The easiest way to make sure it exists or not is to run a query like this:

SELECT * FROM "f1e68fa1-e1fd-4306-8f98-33f981afc8b5".fief_tenants;
JustinGuese commented 9 months ago

Hi, no it does not exist SQL Error [42P01]: ERROR: relation "f1e68fa1-e1fd-4306-8f98-33f981afc8b5.fief_tenants" does not exist Position: 15

That id is listed in fief.public.workspaces though if that helps?

image