New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Json.Decode.list is not consistent #889

Closed
ghivert opened this Issue Aug 1, 2017 · 3 comments

Comments

Projects
None yet
3 participants
@ghivert

ghivert commented Aug 1, 2017

Hi!

Encountered a bug today with decoders. Here's the case:

decodeUserPhotos : Decoder (List UserPhoto)
decodeUserPhotos =
  Decode.list decodeUserPhoto

decodeUserPhoto : Decoder UserPhoto
decodeUserPhoto =
  Decode.succeed UserPhoto
    |: (Decode.field "id" Decode.int)
    |: (Decode.field "cloudinary_id" Decode.string)

Used with a list like this:

[
  {"id":3,"user_id":1,"cloudinary_id":"xxxxxx"},
  {"id":2,"user_id":1,"cloudinary_id":"yyyyyy"},
  {"id":1,"user_id":1,"cloudinary_id":"zzzzzz"}
]

On Chrome Mac, I got:

[ UserPhoto 1 "zzzzzz"
, UserPhoto 2 "yyyyyy"
, UserPhoto 3 "xxxxxx"
]

But on Chrome Windows, I got:

[ UserPhoto 3 "xxxxxx"
, UserPhoto 2 "yyyyyy"
, UserPhoto 1 "zzzzzz"
]

I just got the correct behavior by adding a Json.Decode.map (List.sortBy .id) after decodeUserPhotos. I think the output list should be consistent, whatever browser you're using.
I imagine it is browser specific?

@process-bot

This comment has been minimized.

Show comment
Hide comment
@process-bot

process-bot Aug 1, 2017

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

process-bot commented Aug 1, 2017

Thanks for the issue! Make sure it satisfies this checklist. My human colleagues will appreciate it!

Here is what to expect next, and if anyone wants to comment, keep these things in mind.

@evancz evancz added the no sscce label Aug 1, 2017

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Aug 1, 2017

Member

Edit your post to have an http://sscce.org/. Get rid of the dependency on that JSON helper package. Just use the core Json.Decode functions. This helps minimize the issue and ensure that it really is a core thing.

Member

evancz commented Aug 1, 2017

Edit your post to have an http://sscce.org/. Get rid of the dependency on that JSON helper package. Just use the core Json.Decode functions. This helps minimize the issue and ensure that it really is a core thing.

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Aug 1, 2017

Member

Actually, just make a new issue with the SSCCE. I think that'll work better.

Member

evancz commented Aug 1, 2017

Actually, just make a new issue with the SSCCE. I think that'll work better.

@evancz evancz closed this Aug 1, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment