Trying to create a simple upsert operation with object that contains objectId in Codeless. Just want to set “active” property to false for an existing object.
But console error tells me some other column(s) doesn’t have a default value. A) why should upsert care, the fields/columns are not required to have values, and B) the fields/columns already have a value. I’m 100% sure the objectId is correct and the object exists in the database. What could be the issue?
To reproduce: our app id is AE4235E1-DBB7-C6F0-FF4A-E0378B0B2B00. In the container “AK_prod” is a page “Experiments” with a button that, when clicked, runs the upsert block. It has the objectId hardcoded to an item in the relevant table in our database.
I was able to reproduce this, thanks. The reason for this behavior is that the upsert request follows the same rules as the create one. So, in the create operation, those fields that have a NotNull constraint (in your case these are: cost and title) cannot be created because they have no default value and the request does not specify values for those columns.
I have created an internal ticket - BKNDLSS-33316, to discuss this behavior with the team. To see if it can be improved. At this moment I can suggest that you add default values for these columns, remove the NN constraint, or use the update operation.
We will let you know about the ticket when we have any results.
Hi @Marina.Kan thanks for the quick investigation. In this particular use case, we actually never want to create, just update (the title and cost are NotNull constrained but they are already there, in the object in the database which we are trying to update). Would love to use “update” but this is not an operation Backendless offers in the Data API blocks… and I think it’s a little ridiculous to create a transaction (where “update” is an available operation) just for one simple operation of changing a value in a table from True to False
So now that I understand that the problem is related to the NN constraint, I know what to do (we will just feed the upsert with the existing
title of the item, as well as the T/F value to be changed). At least I no longer feel like I’m taking crazy pills, so thanks very much for investigating and explaining!
I recommend you guys let people upsert objects where there is existing data in NN-constrained columns (if that’s an easy change to make), since the constraint wouldn’t be violated . Thank you for all you do!
I have news on your case. We have investigated the behavior and this one is expected. The constraints are checked before the start of the operation, which is "INSERT INTO … ". The updating is the alternative logical branch for the operation INSERT. So the object must satisfy the primary conditions.
In your case, when you know the objectId of the object to be updated, you should use the “Save object in Backendless” block. With an indication of the object required for updating. When you specify the objectId property of the already created object in the body, the save block serves as an update one.
ah ok — so “Save” sounds like the block to use thanks