https://dagster.io/ logo
Title
a

Aaron Hoffer

11/04/2022, 7:10 PM
I recently upgrade to
v1.0.16
and getting
sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread.
errors, however I’m running it in k8s using a postgres backend for jobs/schedules/etc. My jobs are using in memory output storage and I did notice this recent change https://github.com/dagster-io/dagster/pull/10154 and the exceptions are happening in the pods generated for the kubernetes jobs. The jobs seem to complete fine but I’m getting at least one exception per run.
Here’s the full exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 753, in _finalize_fairy
    fairy._reset(pool)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 1004, in _reset
    pool._dialect.do_rollback(self)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 683, in do_rollback
    dbapi_connection.rollback()
sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 139621353035584 and this is thread id 139620698298112.  Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 753, in _finalize_fairy
    fairy._reset(pool)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 1004, in _reset
    pool._dialect.do_rollback(self)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 683, in do_rollback
    dbapi_connection.rollback()
sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 139621353035584 and this is thread id 139620698298112.
p

prha

11/04/2022, 7:33 PM
I’m surprised that the in memory storage is getting invoked at all, especially since you’ve configured storage to run on a postgres backend. Can you confirm that your instance is configured with postgres? Are you executing anything in process as part of your job? Is there any more to the stack in the logs?
a

Aaron Hoffer

11/04/2022, 7:35 PM
local_artifact_storage:
  module: dagster._core.storage.root
  class: LocalArtifactStorage
  config:
    base_dir: /opt/dagster/dagster_home
run_storage:
  module: dagster_postgres.run_storage
  class: PostgresRunStorage
event_log_storage:
  module: dagster_postgres.event_log
  class: PostgresEventLogStorage
  config:
compute_logs:
  module: dagster._core.storage.noop_compute_log_manager
  class: NoOpComputeLogManager
  config: {}
schedule_storage:
  module: dagster_postgres.schedule_storage
  class: PostgresScheduleStorage
  config:
Are you executing anything in process as
Yes I’m using the
in_process_executor
I don’t see anything in dagit, just this logged to stderr
Exception closing connection <sqlite3.Connection object at 0x7f1ed40a2e40>
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 753, in _finalize_fairy
    fairy._reset(pool)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 1004, in _reset
    pool._dialect.do_rollback(self)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 683, in do_rollback
    dbapi_connection.rollback()
sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 139770470790976 and this is thread id 139769816073984.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/pool/base.py", line 255, in _close_connection
    self._dialect.do_terminate(connection)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 689, in do_terminate
    self.do_close(dbapi_connection)
  File "/usr/local/lib/python3.8/site-packages/sqlalchemy/engine/default.py", line 692, in do_close
    dbapi_connection.close()
sqlite3.ProgrammingError: SQLite objects created in a thread can only be used in that same thread. The object was created in thread id 139770470790976 and this is thread id 139769816073984.
p

prha

11/04/2022, 8:10 PM
Using the in_process_executor should be fine… I’m wondering if you’re using the testing API on jobs or ops, e.g.
my_job.execute_in_process()
AFAICT, the in memory storage implementations are only used in our unit tests. I could see this impacting you if you were kicking off untracked runs on ephemeral storage by using our test APIs within a thread. This is unrelated to the
mem_io_manager
which it sounds like you’re using and does not use SQLite.
a

Aaron Hoffer

11/04/2022, 8:17 PM
Oh sorry, not that I’m aware of. I do have
run_monitoring
on (only other random config I could think of)
i

Issac Loo

11/29/2022, 5:21 PM
@Nicolas May
a

Alexander Osipov

12/03/2022, 7:54 AM
Have same problem. Suppose that the reason because using sensor and dagster.build_resources:
@sensor(job=...)
def some_sensor():
    with build_resources({'some_db': pg_database}) as resources:
        ...
As I see calling
build_resources
with no
instance
argument creates
DagsterInstance
using
DagsterInstance.ephemeral()
method. In this method
InMemoryRunStorage
and
InMemoryEventLogStorage
uses. They use sqlite during initialization.
Yes, it was the problem for my case. Fixed with next changes
@sensor(job=...)
def some_sensor(context):
    with build_resources(
            {'some_db': pg_database},
            instance=context.instance,
    ) as resources:
        ...
p

prha

12/07/2022, 12:12 AM
The fix for this should be rolled out in this week’s release: https://github.com/dagster-io/dagster/pull/10851
🎉 3
:thank-you-box: 3
n

Nicolas May

12/07/2022, 11:43 AM
@Issac Loo
p

prha

12/08/2022, 10:44 PM
This is now out as part of
1.1.6
. Thanks everyone!
❤️ 1