https://dagster.io/ logo
Title
r

Raphaël Riel

02/16/2022, 3:00 PM
Hello! Does anyone have experience in using dotenv while running a local agent? I'm not sure how to integrate the
load_env
call before dagster is booting.
d

daniel

02/16/2022, 3:31 PM
Hi Raphaël - I'm not deeply familiar with dotenv, but looking through the docs, I think load_dotenv call inline right in the Python file that defines your Dagster code (before any code that needs those environment variables to be available runs) could do the trick?
r

Raphaël Riel

02/16/2022, 4:00 PM
I'll try! So somewhere in the Repository file should make it?
d

daniel

02/16/2022, 4:01 PM
Yeah, I think early on in the file or module that you're telling dagster to use to load your code
r

Raphaël Riel

02/16/2022, 4:05 PM
Thanks Daniel!
d

daniel

02/16/2022, 4:06 PM
np - let me know how it goes. I haven't tried this myself so it's possible there will be some gotchas
r

Raphaël Riel

02/16/2022, 4:28 PM
Seems like everything is working except for
DAGSTER_HOME
when put in the repository's file.
This causes Dagster to use a new storage location for every invocation.
Which might not be a problem for local dev...
d

daniel

02/16/2022, 4:32 PM
Hm, strange, when you say it isn't working - you're putting DAGSTER_HOMe in your dotenv file, but its getting ignored or overwritten?
r

Raphaël Riel

02/16/2022, 4:33 PM
Ignored.
Probably that having dot_env operate from the repo, it's added to Env after Dagster is trying to read it.
I also tried putting it in
os.environ
from the repo code (bypassing dot-env). Same result.
d

daniel

02/16/2022, 4:35 PM
Hmmm,
dagster job execute
actually isn't technically supported in dagster cloud currently (although it appears it is working in some fashion). Does the same problem happen if you launch a run from within Dagit in Dagster Cloud?
r

Raphaël Riel

02/16/2022, 4:35 PM
Let me see
Looks like the Env is picked-up by Dagster when I run an agent from my machine and execute a Run from the Cloud.
d

daniel

02/16/2022, 4:37 PM
ah great!
We should add a replacement for
dagster job execute
for cloud, I'll make sure that gets tracked.
r

Raphaël Riel

02/16/2022, 4:38 PM
What would you suggest I do to test my jobs straight from my CLI?
d

daniel

02/16/2022, 4:38 PM
(and probably have it fail if you try to use it in cloud instead of mostly work)
r

Raphaël Riel

02/16/2022, 4:38 PM
I like the idea of launching a run straight from my IDE's terminal.
d

daniel

02/16/2022, 4:38 PM
Yeah, it's an entirely reasonable request
r

Raphaël Riel

02/16/2022, 4:38 PM
And potentially having a debugger attached.
Is this a valid way of doing such a thing?
(It's working)
d

daniel

02/16/2022, 4:42 PM
I was about to recommend that as a slightly unsatisfying alternative yeah 🙂
r

Raphaël Riel

02/16/2022, 4:42 PM
lol
What's the caveats?
d

daniel

02/16/2022, 4:42 PM
Although I think setting DAGSTER_HOME separately outside of the call to
dagster job execute
call would work as well
i.e. setting in the system environment. I think the problem you're running into is that DAGSTER_HOME is really a dagster system env var, so by the time you load it in your job code, it's too late
r

Raphaël Riel

02/16/2022, 4:44 PM
Exact. That was another option I'm willing to try.
d

daniel

02/16/2022, 4:44 PM
The only caveat is that its annoying to have to write your own script vs. using a CLI
r

Raphaël Riel

02/16/2022, 4:45 PM
I'm actually ok with adding the
__main__
thing in file that contains graph/jobs I want to run locally for development purposes.
d

daniel

02/16/2022, 4:46 PM
Ah, OK. in that case that sounds great, execute_in_process is 100% supported in cloud
r

Raphaël Riel

02/16/2022, 4:46 PM
And when the file is loaded by the repo... it should skip this
if
anyway and act as a normal agent?
Since the file won't be executed directly.