REST API v2: POST update gives error 400 on (notNull Unique) field already filled

Hello,

I’m trying to POST an update for an Entity (Passenger) having a foreign key (lastOnBoardShift).
Passenger has several Mandatory or Unique attributes and just one which is both (taxCode).
I want to update lastOnBoardShift only, on Passenger instances having taxCode -obviously- already defined.

Here some Python code:


    def update_passenger(self, token, passenger):

        passenger_id = passenger['id'].encode('ascii', 'ignore')
        url = '%s/app/rest/v2/entities/bustrack$Passenger/%s' % (self.addr, passenger_id)
        auth_header = 'Bearer ' + token['access_token'].encode('ascii', 'ignore')
        headers = {'Authorization': auth_header, 'content-type': 'application/json'}

        entity_json = json.dumps({'lastOnBoardShift': passenger['lastOnBoardShift']})

        resp = requests.put(url=url, data=entity_json, headers=headers)

        return resp

The HTTP response is always 400, and the reason is I don’t provide the taxCode.

If I put the taxCode again in the HTTP json data everything works as expected


entity_json = json.dumps({'taxCode': passenger['taxCode'], 'lastOnBoardShift': passenger['lastOnBoardShift']})

What is wrong?
Besides, I don’t have errors in the Tomcat log

Thanks

Hi,
what platform version do you use and what is the exact error text you get back?

Hello Max,
I’m using Cuba 6.5.1, REST API v2, and the Http response error code is [400]. Here’s the error message content:
’[{“message”:“may not be null”,“messageTemplate”:"{javax.validation.constraints.NotNull.message}",“path”:“taxCode”,“invalidValue”:null}]'
Oddly I don’t get any Error message in the Tomcat log
PS there’s an error in the question… I’m using a PUT request (not POST) as the code shows, my bad!

That’s a bug. Fields that are not passed in the request body for update should not be validated. See the related issue.

Thank you Max,
I’ll look forward to it…

Oh! I see you just fixed it! Great!!!
Thank you

You’re welcome:) The fix will appear in v 6.6.4

:ticket: See the following issue in our bug tracker:

https://youtrack.cuba-platform.com/issue/PL-9711