Hi quick question about `prefect.context`. In my c...
# prefect-community
j
Hi quick question about
prefect.context
. In my config.toml, a context variable is defined like
foo = "202010"
. In the task definition, it’s used like
year = prefect.context.foo[:4]
but it causes
int object is not subscriptable
error. Is there a way to make it work without doing
str(foo[:4])
?
j
Things that look like integers in the
config.toml
are automatically loaded as integers unfortunately. If you add any non-numeric characters to that it would remain a string.
j
Interesting. Thank you!
Is there a way to have different set of context variables for different projects?
The documentation seems to show one [Context] section in config.toml.
j
If you're running without cloud/server, you can always configure the context programmatically:
Copy code
with prefect.context(foo=...):
    flow.run()
j
I am running with the server for concurrency.
j
If you're running with cloud/server, I recommend not configuring things from within context, as its not as easy to port to different runtime environments. Ideally any parameters you need at runtime would be passed in as
Parameter
tasks, or constants in the flow code.
Using context will work though if you really want to use it. If you want different config for different environments, you can pass a specific config path as
PREFECT__USER_CONFIG_PATH
j
I see. Thank you!