feathersjs-ecosystem / feathers-reactive

Reactive API extensions for Feathers services
MIT License
216 stars 37 forks source link

Several issues on 'update' #18

Closed j2L4e closed 8 years ago

j2L4e commented 8 years ago

Say I have a 'messages' service with 3 existing messages. I query those via .find() and subscribe:

{
  "total": 3,
  "limit": 5,
  "skip": 0,
  "data": [
    {
      "text": "read me!",
      "id": 0
    },
    {
      "text": "read me!",
      "id": 1
    },
    {
      "text": "read me!",
      "id": 2
    }
  ]
}

I now change one of the messages (id 1) using cURL. The Observable emits the following object:

{
  "total": 0,
  "limit": 5,
  "skip": 0,
  "data": [
    {
      "text": "read me!",
      "id": 0
    },
    {
      "text": "read me!",
      "id": 1
    },
    {
      "text": "I changed",
      "id": "1"
    },
    {
      "text": "read me!",
      "id": 2
    }
  ]
}

Several things are unexpected:

daffl commented 8 years ago

What does your setup look like? I think that most of the weirdness is happening because the id is converted to a string. You may have to parseInt it in a before hook for update and patch.

j2L4e commented 8 years ago

I checked and on the wire 'id' is a string already. 42["messages updated",{"text":"I changed another time","id":"1"}] So it appears to be a server-side problem. Sorry for the confusion.

I created the server using the CLI. 'generate', 'generate service'. No auth, memoryDB. However, this is totally a bug. Want me to file it somewhere else?

edit: can confirm that updating the same entry again (id "1") works as expected.

daffl commented 8 years ago

Oh, I wasn't saying this isn't a bug, I'm just trying to figure out how to reproduce it. From what I got:

j2L4e commented 8 years ago

Never had the feeling you were!

Yep, POSTing works fine, the problem occurs after PUTting a new value:

$ curl 'http://localhost:3030/messages' -H 'Content-Type: application/json' --data-binary '{ "text": "read me!" }'
{"text":"read me!","id":0}
$ curl 'http://localhost:3030/messages' -H 'Content-Type: application/json' --data-binary '{ "text": "read me!" }'
{"text":"read me!","id":1}
$ curl 'http://localhost:3030/messages/1' --request PUT  -H 'Content-Type: application/json' --data-binary '{ "text": "I changed" }'
{"text":"I changed","id":"1"}  
daffl commented 8 years ago

This was a bug in feathers-memory that has been fixed with https://github.com/feathersjs/feathers-memory/pull/26. I think most other database adapters should not have that problem. Thanks for reporting!