Thanks @WillFG for posting this thread and @dfunckt for working on a fix. I’m just getting started with an openbalena self-hosted server and ran into the same database error when attempting to set env vars. @dfunckt is there a Github issue that we can follow for the fix? Or perhaps there is a workaround that you identified? Thanks.
@dfunckt any ETA on a fix for this? If you think it is likely to be more than a couple of months I just need to come up with a workaround. Thanks for all the help.
Hey @WillFG, apologies for the delay – while it might seem that we only need to change the code to refer to the field appropriately, that would break config vars on balenaCloud (balenaCloud is now built on top of openBalena). So we’re working on refactoring a few things and moving them to open-balena which will properly fix the issue and also allow us to do other cool things such as being able to transparently introduce new API versions while maintaining compatibility with older ones. It’s a bunch of work but we’re getting there.
I though I posted this before but it seems I haven’t. You can workaround the issue by doing HTTP requests directly to the API, like so:
# creates a new application config variable
# similar request works for `device_config_variable` as well
curl -X POST 'https://api.myopenbalena.com/v5/application_config_variable' \
-H 'authorization: Bearer <TOKEN>' \
-H 'content-type: application/json' \
--data-binary '{"application": <APPID>,"name":"<KEY>","value":"<VALUE>"}'
# creates a new application environment variable
# similar request works for `device_environment_variable` as well
curl -X POST 'https://api.myopenbalena.com/v5/application_environment_variable' \
-H 'authorization: Bearer <TOKEN>' \
-H 'content-type: application/json' \
--data-binary '{"application": <APPID>,"env_var_name":"<KEY>","value":"<VALUE>"}'
# updates the value of an application config variable.
# similar request works for `device_config_variable` as well
curl -X PATCH 'https://api.myopenbalena.com/v5/application_config_variable(<ID>)' \
-H 'authorization: Bearer <TOKEN>' \
-H 'content-type: application/json' \
--data-binary '{"value":"<VALUE>"}'
# updates the value of an application environment variable
# similar request works for `device_environment_variable` as well
curl -X PATCH 'https://api.myopenbalena.com/v5/application_environment_variable(<ID>)' \
-H 'authorization: Bearer <TOKEN>' \
-H 'content-type: application/json' \
--data-binary '{"value":"<VALUE>"}'
You’ll need to adjust accordingly if you’re using self-signed certificates, as it happens by default – passing --cacert <PATH_TO_CERT> should do it for curl.
Note that these queries will stop working as soon as the issue is fixed.
take the ID out of quotes, as it should be an integer
confirm that a device environment variable with the same name, for that device, doesn’t exist; if it does then you should be using a PATCH method, not POST.
@WillFG environment variables were always supported – it’s only config variables that weren’t (and actually still aren’t) via the CLI – i.e. those prefixed with RESIN_ or BALENA_.