Skip to content

PUT creates new DynamoDB entity when hash/range key are specified in body [DATAREST-1025] #1387

Open
@spring-projects-issues

Description

@spring-projects-issues

Ryon Day opened DATAREST-1025 and commented

I use Spring-Data-DynamoDB and have been updating dependencies.

I have an org.springframework.core.convert.converter.Converter registered to be able to reference my DynamoDB entities from Spring-Data-Rest using their hash/range keys, so:
http://service/foo/hash-range will get the DynamoDB entity with hash and range keys hash and range. This integrates well with Spring-data-rest and the AWS API which uses composite key objects.

@Component
public class StringToFooIdConverter implements Converter<String, FooId> {
    // Conversion
}

Let's say that bar and baz fields are the hash and range key properties for the Foo object.

This means that we create a new entity by

{
    "bar": "qux", 
    "baz": "garple", 
    "some_other_thing": "quux" 
}

And then we get the same entity with

{
    "bar": "qux", 
    "baz": "garple", 
    "some_other_thing": "quux" 
}

Cool! We also need to be able to PUT to replace. This is where the problem comes in.

Spring-Data-REST 2.4.4.RELEASE

Request

{
    "bar": "qux2", 
    "baz": "garple2", 
    "some_other_thing": "quux2" 
}

Response

{
    "bar": "qux", 
    "baz": "garple", 
    "some_other_thing": "quux2" 
}

Cool! It recognized that since this is a key/value store, you'd actually be changing the id, so it did not do it!

Request

{
    "some_other_thing": "quux3" 
}

Response

{
    "bar": "qux", 
    "baz": "garple", 
    "some_other_thing": "quux2" 
}

Cool! since the key was specified on the URL, it got it, updated the record, and returned the whole thing! Works like a champ.

Spring-Data-REST 2.6.1.RELEASE

Request

{
    "bar": "qux2", 
    "baz": "garple2", 
    "some_other_thing": "quux2" 
}

Response

{
    "bar": "qux2", 
    "baz": "garple2", 
    "some_other_thing": "quux2" 
}

Oh dear! It created a NEW record, and the old one still exists too! It did not respect that the attributes were keys!

Request

{
    "some_other_thing": "quux3" 
}

Response

{
  "error": "invalid_request",
  "error_description": "Message not readable"
}

Oh dear! It would seem that there is some weirdness here, because it tries to create a new object (or something) and cannot do so.

Desired State

This functionality should be the same as Spring-Data-Rest 2.4.4.RELEASE


Affects: 2.6.1 (Ingalls SR1), 2.5.8 (Hopper SR8)

Metadata

Metadata

Assignees

Labels

type: regressionA regression from a previous release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions