MMGIS
MMGIS copied to clipboard
Version is not actually optional in Backend API Upsert
If you attempt to upsert a mission without a version number in the request body it returns a 200 with "Failed to find mission."
Could you provide an example curl command that fails this way.
I retested it locally and it does work without a version
specified. And going off of the "Failed to find mission."
error, are you sure the mission
name you passed it exists and that MMGIS' connection to the database was properly established.
How about some screenshots?
With Version
Without Version:
Yep. In the first image, because you passed "version", it took that version's configuration object and updated (made a next version of) the configuration. v2 and v67 of that mission's configuration objects would be identical now.
In the second image, it's just failing because you're passing an empty config
to it. If you want to fully test it, you could download a configuration from the Overall Tab in the /configure page and copy that value into the body.
In the first image im also passing an empty config though.
Yeah, but version
takes precedence.
Like:
if(body.version != null) {
body.config = getMissionConfig(body.mission, body.version)
}
upsertConfig(body.config)
But if I save a version... and try to override the config with an empty object. Shouldn't that error?
I suppose it could. Would it be better to state in the docs that mission
is required and then either version
or config
is required but not both?
Between creating a new record or updating an old one.
Creating a new mission I would expect the config object to error, absolutely when its empty. But if I update a version with an empty config, I would also expect that to error as well.
Since upsert combines both logically. I would expect it to follow the same rules. So on upsert an empty config or incorrect config, make it error. That would solve everything.
There's still some misunderstanding so hopefully this helps.
- /api/configure/upsert will never create new missions -- it will only ever update existing mission configurations
- You never update a specific version of the configuration -- it will always create a new/next version.
version
andconfig
are both inputs.
In its simplest, the endpoint works like this:
const configs = { missionA: ['config1', 'config2', 'config3'] }
function upsert(mission, version, config) {
if( version != null ) config = configs[mission][version]
configs[mission].push(config)
}
upsert("missionA", 0)
// => configs = { missionA: ['config1', 'config2', 'config3', 'config1'] }
upsert('missionA', null, 'myConfig')
// => configs = { missionA: ['config1', 'config2', 'config3', 'config1', 'myConfig'] }
upsert("missionA", 4)
// => configs = { missionA: ['config1', 'config2', 'config3', 'config1', 'myConfig', 'myConfig'] }