Attributes via IMWS.post('v1/attributes') do not respect "unique only" fields

Started by Jingo, October 20, 2019, 10:25:13 PM

Previous topic - Next topic

Jingo

Hi Mario - just discovered something that I didn't expect.. curious as to your thoughts....

1- I created a new Attribute Schema: APP-Gallery with 4 fields.  I did not set any fields to unique.
2- I used my APP-Gallery to fill the fields for a single image
3- I realized that if I did the action twice, it would duplicate so I changed one of the fields to unique=true and save the set.
4- I then chose a new image and added the action twice again.. the second duplicate still shows up.
5- If I manually try to add the same info to that field, then the system brings up the unique only warning....



Shouldn't the IMWS.post('v1/attributes', params) command also check for the unique flag as it sets the data and prevent the entire txn from succeeding...?  Or, do you suggest the programmer perform checks before calling the post action to prevent duplicates prior to adding the data?  I didn't see any apps in the system that perform checks so assumed the IMWS function would do so...

I noticed the sample Attributes app does the same thing...



Thx!

Jingo

The more I think on this, the more I guess it makes sense that the APP would need to handle checking the individual fields for unique flags before calling the function...  but it does add a bit of complexity to the app..

For example, I would need to get the schema, setup an array by field and unique flag.  Then, before filing back any data, I would need to get the existing attributes in that schema for each selected image and loop to check each unique field value to compare to the current value being added. 

Was hoping there might be a hidden parameter in the endpoint to auto-validate "unique" fields... :-)

Mario

I have not yet looked into this and I don't remember anymore. Must be two years since I've implemented this endpoint.
I will look into this for one of the next releases. This affects probably only your app.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Jingo

Quote from: Mario on October 21, 2019, 08:11:54 PM
I have not yet looked into this and I don't remember anymore. Must be two years since I've implemented this endpoint.
I will look into this for one of the next releases. This affects probably only your app.

Thanks Mario.. no rush of course.. I can implement some checks and/or just ignore it all together (since no one is likely to use my Gallery App any way...)  Appreciate your thoughts and time...  Andy.

Mario

The unique constraint was enforced by IMatch, not by the Attribute database subsystem.
I have now moved the check to the subsystem and you cannot longer insert duplicate attribute values.

I have updated the sample application as well. It no longer uses a unique attribute for the "insert two records" button because otherwise pressing the button multiple times would cause irritation to the user testing the sample app.

These changes will be included in IMatch 2020.

Until then I suggest you select the data in your set to check for existing values before inserting.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

Jingo

Thanks very much Mario.... this will take a bit of load off the application code and make using the endpoint much simpler!! 

Much appreciate your time to look into this...  ;D