Environment variable substitution is not working for me when connecting GE to my database

A user asked this question on Slack - reposting it here, since others might run into this issue as well.

The user wanted to provide the database username and password to GE using env variables (following this doc: https://docs.greatexpectations.io/en/latest/reference/data_context_reference.html#managing-environment-and-secrets)

The user used the ${…} syntax in the uncommitted/config_variables.yml, but GE would not connect to the database and it was clear that the env vars are not being substituted:

image (1)

Here is why this did not work:

Data Context configuration supports the substitution syntax only in the great_expectations.yml config file, so any ${…} in config_variables.yml is not going to be substituted.

If you want to pass the database password to a datasource via an env var, modify this datasource’s config block in great_expectations.yml:

Before:

datasources:
    datawarehouse:
        class_name: SqlAlchemyDatasource
        data_asset_type:
            class_name: SqlAlchemyDataset
        module_name:
        credentials: ${datawarehouse}

After:

datasources:
    datawarehouse:
        class_name: SqlAlchemyDatasource
        data_asset_type:
            class_name: SqlAlchemyDataset
        module_name:
        credentials:
            drivername: postgresql+psycopg2
            host: myhost.foo
            port: '5439'
            database: mydatabase
            username: ${DATAWAREHOUSE_USERNAME}
            password: ${DATAWAREHOUSE_PASSWORD}

(DATAWAREHOUSE_USERNAME and DATAWAREHOUSE_PASSWORD are env variables)

What version of GE is this in… with v0.12.6 of the framework all env vars are being substitued in the GE file from env vars sans the password field

I don’t want to hard code the password into this file since it breaks my company’s security standards

1 Like

Hi @tom.mitic! Today we are in the process of releasing GE v0.12.7 which fixes this issue and also allows for multiple substitutions per line. It should be released today! Apologies for the inconvenience and the original change, it was inadvertent - we were trying to fix a different bug.

Ok thanks for the update

1 Like

FYI we just released v0.12.7 - please let us know if this does not solve your issue!

It worked for us. And has unblocked our workflow.

2 Likes