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

Database env vars are not read #5941

Closed
qiisziilbash opened this issue Jun 3, 2024 · 4 comments
Closed

Database env vars are not read #5941

qiisziilbash opened this issue Jun 3, 2024 · 4 comments
Labels
community:needs-information Evaluated by community team, needs information community:reviewed Issue has been reviewed by the Label Studio Community Team.

Comments

@qiisziilbash
Copy link

qiisziilbash commented Jun 3, 2024

Describe the bug
I set following env vars in .env alongside with other env vars (e.g. LABEL_STUDIO_PORT) and run the app like this:

python -m venv venv
source venv/bin/activate
pip install label-studio
# create and set .env file
label-studio --no-browser --data-dir .
LABEL_STUDIO_PORT=9001

DJANGO_DB=default
POSTGRE_HOST=host.dummy
POSTGRE_NAME=db
POSTGRE_USER=user
POSTGRE_PASSWORD=dummy
POSTGRE_PORT="5432"

It sees some vars (e.g. LABEL_STUDIO_PORT) but not db vars (see this). I printed the db vars (right before connection) and it was all default values:

{'database': 'postgres', 'user': 'postgres', 'password': 'postgres', 'host': 'localhost', 'port': 5432}

Expected behavior
I was expecting to connect to db using my env vars not the default vars. I think the process that is running the main app sees the env vars but not the process that is running the python code for the db connection

Additional context

Traceback (most recent call last):
  File "/Users/user_name/venv/lib/python3.11/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
    self.connect()
  File "/Users/user_name/venv/lib/python3.11/site-packages/sentry_sdk/utils.py", line 1711, in runner
    return sentry_patched_function(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user_name/venv/lib/python3.11/site-packages/sentry_sdk/integrations/django/__init__.py", line 671, in connect
    return real_connect(self)
           ^^^^^^^^^^^^^^^^^^
  File "/Users/user_name/venv/lib/python3.11/site-packages/django/utils/asyncio.py", line 33, in inner
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user_name/venv/lib/python3.11/site-packages/django/db/backends/base/base.py", line 200, in connect
    self.connection = self.get_new_connection(conn_params)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user_name/venv/lib/python3.11/site-packages/django/utils/asyncio.py", line 33, in inner
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user_name/venv/lib/python3.11/site-packages/django/db/backends/postgresql/base.py", line 188, in get_new_connection
    connection = Database.connect(**conn_params)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user_name/venv/lib/python3.11/site-packages/psycopg2/__init__.py", line 122, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
psycopg2.OperationalError: connection to server at "localhost" (::1), port 5432 failed: FATAL:  password authentication failed for user "postgres"


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

Traceback (most recent call last):
  File "/Users/user_name/venv/bin/label-studio", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/Users/user_name/venv/lib/python3.11/site-packages/label_studio/server.py", line 302, in main
    _apply_database_migrations()
  File "/Users/user_name/venv/lib/python3.11/site-packages/label_studio/server.py", line 65, in _apply_database_migrations
    if not is_database_synchronized(DEFAULT_DB_ALIAS):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user_name/venv/lib/python3.11/site-packages/label_studio/server.py", line 58, in is_database_synchronized
    executor = MigrationExecutor(connection)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user_name/venv/lib/python3.11/site-packages/django/db/migrations/executor.py", line 18, in __init__
    self.loader = MigrationLoader(self.connection)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user_name/venv/lib/python3.11/site-packages/django/db/migrations/loader.py", line 53, in __init__
    self.build_graph()
  File "/Users/user_name/venv/lib/python3.11/site-packages/django/db/migrations/loader.py", line 220, in build_graph
    self.applied_migrations = recorder.applied_migrations()
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user_name/venv/lib/python3.11/site-packages/django/db/migrations/recorder.py", line 77, in applied_migrations
    if self.has_table():
       ^^^^^^^^^^^^^^^^
  File "/Users/user_name/venv/lib/python3.11/site-packages/django/db/migrations/recorder.py", line 55, in has_table
    with self.connection.cursor() as cursor:
         ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user_name/venv/lib/python3.11/site-packages/django/utils/asyncio.py", line 33, in inner
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user_name/venv/lib/python3.11/site-packages/django/db/backends/base/base.py", line 259, in cursor
    return self._cursor()
           ^^^^^^^^^^^^^^
  File "/Users/user_name/venv/lib/python3.11/site-packages/django/db/backends/base/base.py", line 235, in _cursor
    self.ensure_connection()
  File "/Users/user_name/venv/lib/python3.11/site-packages/django/utils/asyncio.py", line 33, in inner
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user_name/venv/lib/python3.11/site-packages/django/db/backends/base/base.py", line 218, in ensure_connection
    with self.wrap_database_errors:
  File "/Users/user_name/venv/lib/python3.11/site-packages/django/db/utils.py", line 90, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/Users/user_name/venv/lib/python3.11/site-packages/django/db/backends/base/base.py", line 219, in ensure_connection
    self.connect()
  File "/Users/user_name/venv/lib/python3.11/site-packages/sentry_sdk/utils.py", line 1711, in runner
    return sentry_patched_function(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user_name/venv/lib/python3.11/site-packages/sentry_sdk/integrations/django/__init__.py", line 671, in connect
    return real_connect(self)
           ^^^^^^^^^^^^^^^^^^
  File "/Users/user_name/venv/lib/python3.11/site-packages/django/utils/asyncio.py", line 33, in inner
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user_name/venv/lib/python3.11/site-packages/django/db/backends/base/base.py", line 200, in connect
    self.connection = self.get_new_connection(conn_params)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user_name/venv/lib/python3.11/site-packages/django/utils/asyncio.py", line 33, in inner
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user_name/venv/lib/python3.11/site-packages/django/db/backends/postgresql/base.py", line 188, in get_new_connection
    connection = Database.connect(**conn_params)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user_name/venv/lib/python3.11/site-packages/psycopg2/__init__.py", line 122, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
django.db.utils.OperationalError: connection to server at "localhost" (::1), port 5432 failed: FATAL:  password authentication failed for user "postgres"

Sentry is attempting to send 2 pending events
Waiting up to 2 seconds
Press Ctrl-C to quit
@sajarin
Copy link
Contributor

sajarin commented Jun 4, 2024

What version of Label Studio is this?

@sajarin sajarin added community:needs-information Evaluated by community team, needs information community:reviewed Issue has been reviewed by the Label Studio Community Team. labels Jun 4, 2024
@qiisziilbash
Copy link
Author

qiisziilbash commented Jun 4, 2024

latest: 1.12.1

@sajarin
Copy link
Contributor

sajarin commented Jun 4, 2024

Are you running this with Docker?

What happens when you just manually export the environment variables in your shell before running Label Studio?


   export LABEL_STUDIO_PORT=9001
   export DJANGO_DB=default
   export POSTGRE_HOST=host.dummy
   export POSTGRE_NAME=db
   export POSTGRE_USER=user
   export POSTGRE_PASSWORD=dummy
   export POSTGRE_PORT=5432

   # Activate your virtual environment
   source venv/bin/activate

   # Run Label Studio
   label-studio --no-browser --data-dir .

@qiisziilbash
Copy link
Author

Are you running this with Docker?
No

I don't know what was the issue but seems like it is gone now and now it is reading from env fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community:needs-information Evaluated by community team, needs information community:reviewed Issue has been reviewed by the Label Studio Community Team.
Projects
None yet
Development

No branches or pull requests

2 participants