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

ORM error with MySQL backend #115

Closed
MattiaFailla opened this issue Nov 24, 2022 · 5 comments
Closed

ORM error with MySQL backend #115

MattiaFailla opened this issue Nov 24, 2022 · 5 comments
Labels
bug Something isn't working

Comments

@MattiaFailla
Copy link

MattiaFailla commented Nov 24, 2022

Describe the bug

Hi Team, following the self-hosted docker-compose guide with MYSQL database the following error is issued:

fief-server_1  | WorkspaceDatabaseConnectionError: (pymysql.err.OperationalError) (1170, 
fief-server_1  | "BLOB/TEXT column 'message' used in key specification without a key length")
fief-server_1  | [SQL: CREATE INDEX ix_fief_audit_logs_message ON fief_audit_logs (message)]

To Reproduce

Steps to reproduce the behavior:

  1. Create the docker-compose as in the tutorial
  2. Configure the .env file with the data outputted after the configuration container (docker run -it --rm ghcr.io/fief-dev/fief:latest fief quickstart --docker)
  3. Edit .env file and configure a mysql database
  4. Execute docker-compose up

Expected behavior

Fief server should start and migration should be performed with a MySQL backend.

Configuration

  • Cloud or self-hosted: self-hosted
  • If self-hosted, Fief version: ghcr.io/fief-dev/fief:latest (sha256:31bba98a0d386a81ac5a5d4971904d8b1cedcb15c767c71f1ff5727cdc68db04)

Additional context

Here is the full log:

fief-server_1  | │ ╭───────────────────────────────── locals ─────────────────────────────────╮ │
fief-server_1  | │ │                         config = <alembic.config.Config object at        │ │
fief-server_1  | │ │                                  0x7f36ed0281c0>                         │ │
fief-server_1  | │ │                     connection = <sqlalchemy.engine.base.Connection      │ │
fief-server_1  | │ │                                  object at 0x7f36ecfd7a00>               │ │
fief-server_1  | │ │ database_connection_parameters = (                                       │ │
fief-server_1  | │ │                                  │                                       │ │
fief-server_1  | │ │                                  mysql+pymysql://root:***@db:3306/fasta… │ │
fief-server_1  | │ │                                  │   {}                                  │ │
fief-server_1  | │ │                                  )                                       │ │
fief-server_1  | │ │                         engine = Engine(mysql+pymysql://root:***@db:330… │ │
fief-server_1  | │ │                    schema_name = 'f6a6bc6b-dd82-4414-b92f-e9c8bfcf8097'  │ │
fief-server_1  | │ │                           self = <fief.services.workspace_db.WorkspaceD… │ │
fief-server_1  | │ │                                  object at 0x7f36ecfd7040>               │ │
fief-server_1  | │ ╰──────────────────────────────────────────────────────────────────────────╯ │
fief-server_1  | ╰──────────────────────────────────────────────────────────────────────────────╯
fief-server_1  | WorkspaceDatabaseConnectionError: (pymysql.err.OperationalError) (1170, 
fief-server_1  | "BLOB/TEXT column 'message' used in key specification without a key length")
fief-server_1  | [SQL: CREATE INDEX ix_fief_audit_logs_message ON fief_audit_logs (message)]
fief-server_1  | (Background on this error at: https://sqlalche.me/e/14/e3q8)

errorlog.txt

@MattiaFailla MattiaFailla added the bug Something isn't working label Nov 24, 2022
@fief-bailiff
Copy link

fief-bailiff bot commented Nov 24, 2022

Hail, @MattiaFailla 👋 Welcome to Fief's kingdom!

Our team will get back to you very soon to help.

In the meantime, take a minute to star our repository ⭐️

star-fief

Farewell!

@frankie567
Copy link
Member

Hello @MattiaFailla 👋

Hmm, that's indeed an error during the creation of the database schema. It's strange because Fief is tested against MySQL during CI.

Could you tell me which version of MySQL you are using?

@MattiaFailla
Copy link
Author

MattiaFailla commented Nov 28, 2022

Hey @frankie567

I'm using MySQL Server 8.0.31-1.el8

Here is the docker-compose file:
(Please note that I've specified the 0.18 Fief-server version just for testing but this issue is present in every Fief version.)

version: '3'

services:
  db:
    image: mysql
    ports:
      - "0.0.0.0:3308:3306"
    env_file:
      - .env

  fief-server:
    image: ghcr.io/fief-dev/fief:0.18
    command: fief run-server --port 8585
    depends_on:
      - db
    expose:
      - 8585
    env_file:
      - .env

  fief-worker:
    image: ghcr.io/fief-dev/fief:latest
    command: fief run-worker -p 1 -t 1
    env_file:
      - .env

  redis:
    image: redis:alpine
    command: redis-server --save 60 1 --loglevel warning
    volumes:
      - redis-data:/data

volumes:
  redis-data:

And this is the .env

DEBUG=True
MYSQL_DATABASE=fastapi
MYSQL_ROOT_PASSWORD=root

# Reference: https://docs.fief.dev/self-hosting/environment-variables/

SECRET=XXX
FIEF_CLIENT_ID=XXX
FIEF_CLIENT_SECRET=XXX
ENCRYPTION_KEY=XXX=
PORT=8000
ROOT_DOMAIN=localhost:8000
FIEF_DOMAIN=localhost:8000
FIEF_MAIN_USER_EMAIL=test@example.com
FIEF_MAIN_USER_PASSWORD=exampleexample
CSRF_COOKIE_SECURE=False
LOGIN_SESSION_COOKIE_SECURE=False
SESSION_COOKIE_SECURE=False
FIEF_ADMIN_SESSION_COOKIE_SECURE=False


# Read more: https://docs.fief.dev/self-hosting/deployment/setup-database/
DATABASE_TYPE=MYSQL
DATABASE_HOST=db
DATABASE_PORT=3306
DATABASE_USERNAME=root
DATABASE_PASSWORD=root
DATABASE_NAME=fastapi

REDIS_URL=redis://redis:6379

LOGIN_SESSION_COOKIE_NAME=login_session_data
REGISTRATION_SESSION_COOKIE_NAME=registration_session_data

@fief-bailiff
Copy link

fief-bailiff bot commented Nov 28, 2022

Hail, @MattiaFailla 👋

I've noticed you shared secret values: SECRET, FIEF_CLIENT_ID, FIEF_CLIENT_SECRET, ENCRYPTION_KEY. Those are highly sensitive and you should keep them secret.

For your security, I've taken the liberty to replace them with dummy values.

@frankie567
Copy link
Member

Thank you for those details!

So it turns out it works with MariaDB, but not MySQL (🙄). I've added it to our CI so we can catch those errors earlier.

The culprit is actually an index on the message column of the AuditLog model. It's a TEXT column, so it's indeed a bit weird to have an index on this, don't really know why I did this.

I'll push a fix soon!

frankie567 added a commit that referenced this issue Nov 29, 2022
Fixes
-----

* Fix MySQL compatibility (#115). Thanks @MattiaFailla for the report 🎉
* Run count users task only once per day.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants