MMGIS icon indicating copy to clipboard operation
MMGIS copied to clipboard

Version is not actually optional in Backend API Upsert

Open Outridair opened this issue 2 years ago • 9 comments

If you attempt to upsert a mission without a version number in the request body it returns a 200 with "Failed to find mission."

Outridair avatar Feb 09 '23 17:02 Outridair

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.

tariqksoliman avatar Feb 22 '23 23:02 tariqksoliman

How about some screenshots?

With Version Screen Shot 2023-02-23 at 15 10 36

Without Version: Screen Shot 2023-02-23 at 15 10 48

Outridair avatar Feb 23 '23 21:02 Outridair

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.

tariqksoliman avatar Feb 23 '23 21:02 tariqksoliman

In the first image im also passing an empty config though.

Outridair avatar Feb 23 '23 21:02 Outridair

Yeah, but version takes precedence.

Like:

if(body.version != null) {
  body.config = getMissionConfig(body.mission, body.version)
}
upsertConfig(body.config)

tariqksoliman avatar Feb 23 '23 21:02 tariqksoliman

But if I save a version... and try to override the config with an empty object. Shouldn't that error?

Outridair avatar Feb 23 '23 21:02 Outridair

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?

tariqksoliman avatar Feb 23 '23 21:02 tariqksoliman

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.

Outridair avatar Feb 23 '23 21:02 Outridair

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 and config 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'] }

tariqksoliman avatar Feb 23 '23 22:02 tariqksoliman