Skip to content
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

fields_for_query has buggy order-dependent logic #70

Closed
grncdr opened this issue Nov 12, 2015 · 4 comments
Closed

fields_for_query has buggy order-dependent logic #70

grncdr opened this issue Nov 12, 2015 · 4 comments
Assignees
Labels

Comments

@grncdr
Copy link
Contributor

grncdr commented Nov 12, 2015

This comes from ZenDesk, and appears to be a bug on this line.

If the first (locale, fields) tuple in raw_fields does not contain every field name, then the result of fields_for_query can entirely skip fields that do have defined values in other locales.

@dlitvakb
Copy link
Contributor

@grncdr after several tests, I cannot find any unexpected behaviour related to the pointed out method or any *_with_locales field

Tests done:

On a Space with 2 locales with 1 content type, with fields a (localized), b (not localized), created entries like the following (On the UI, then queried with the SDK):

  • {a: {'en-US': 'foo', 'es': 'bar'}, b: nil}

Calling entry.a_with_locales returned: {'en-US': 'foo', 'es': 'bar'}
Calling entry.a returned: 'foo'

  • {a: {'en-US': nil, 'es': 'bar'}, b: nil}

Calling entry.a_with_locales returned: {'en-US': nil, 'es': 'bar'}
Calling entry.a returned: nil

  • {a: nil, b: 'foobar'}

Calling entry.b_with_locales returned: {'en-US': 'foobar', 'es': nil}
Calling entry.b returned: 'foobar'

All of these were the expected results.

Closing, until more information is provided

@dlitvakb dlitvakb self-assigned this Nov 12, 2015
@lluzak
Copy link

lluzak commented Nov 13, 2015

Hey, @dlitvakb, all tests above are correct, but what we are getting from API is:

{
  "fields": {
    "nameIntern": {
      "no-NO": "Animal School Day",
      "dk-DK": "Animal School Day",
      "pl-PL": "Animal School Day",
      "en-US": "Animal School Day",
      "de-DE": "Ein tierischer Schultag",
      "de-AT": "Ein tierischer Schultag",
      "de-CH": "Ein tierischer Schultag",
      "se-SE": "Animal School Day",
      "nl-BE": "Dierenschooldag",
      "nl-NL": "Dierenschooldag"
    },
     "iOsPhoneId": {
      "en-US": "588812258"
    },
    "iOsTabletId": {
      "en-US": "588813273"
    }
}

Because of wrong order of locales in fields ( other entries always have en-US locale as first ), when i call:

entry.i_os_phone_id // "588812258"
entry.i_os_phone_id_with_locales // nil

Problem is in https://github.com/contentful/contentful-management.rb/blob/master/lib/contentful/management/entry.rb#L195, where is assume that default locale in @fields is always first.

My @fields variable looks like:

{
  "no-NO" =>  {
    "nameIntern" => "Animal School Day"
  },
  "en-US" => {
    "nameIntern" => "Animal School Day",
    "iOsPhoneId" => "...",
    "iOsTabletId" => "..."
  }
}

@grncdr grncdr reopened this Nov 13, 2015
@grncdr
Copy link
Contributor Author

grncdr commented Nov 13, 2015

Thanks for providing these extra details @lluzak! AFAIK the ordering of keys in JSON objects (and Ruby hashes) is not something one can depend on, so if the code does that's probably a mistake, and @dlitvakb was lucky with his tests.

@dlitvakb
Copy link
Contributor

@lluzak Oh, the issue makes sense now. Have actually no idea how to generate it so that the default locale is not the first place, but, I got to fix the issue by merging whatever is there from any locale.

PR soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants