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

Fix a serialization bug that randomly skips fields if "x_of" is encountered #1042

Merged
merged 1 commit into from Aug 9, 2017

Conversation

Projects
None yet
2 participants
@Raychee

Raychee commented Jul 28, 2017

The purpose of this PR is to make sure all of the fields are correctly serialized when there are x_of validation rules.

The tricky part of this bug is that it is not stably repeatable. This is because the serialization iterates through the json keys in random order, and the bug shows up only when the fields that contain x_of rules are processed before other fields. In short, the schema variable in function serialize will be overwritten mistakenly in if x_of clause, causing the serialization of the rest of the fields are skipped, due to the ill-formed schema.

Along with this bug fix, the PR also enabled correct serialization under circumstances where x_of appears at the first level of a field's schema whose type is list.

Two new unit test cases are written for these scenarios, and one of them uses OrderedDict to guarantee the traversing order of the json keys.

(This is a repost of PR #1040. Please let me know if there are other improvements I need to make.)

@@ -1,4 +1,5 @@
import time
from collections import OrderedDict

This comment has been minimized.

@nicolaiarocci

nicolaiarocci Aug 8, 2017

Member

This line fails on Python 2.6. Please replace it with:

try:
    from collections import OrderedDict  # noqa
except ImportError:
    # Python 2.6 needs this back-port
    from ordereddict import OrderedDict

This comment has been minimized.

@Raychee

Raychee Aug 9, 2017

Oh, didn't know of that, thanks. I have updated the commit, please have a look.

@nicolaiarocci nicolaiarocci added this to the 0.8 milestone Aug 9, 2017

@nicolaiarocci nicolaiarocci merged commit 7598983 into pyeve:master Aug 9, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

nicolaiarocci added a commit that referenced this pull request Aug 9, 2017

@nicolaiarocci

This comment has been minimized.

Member

nicolaiarocci commented Aug 9, 2017

Thanks!

@Raychee Raychee deleted the Raychee:dev/raychee branch Aug 9, 2017

Amedeo91 pushed a commit to Amedeo91/eve that referenced this pull request Aug 11, 2017

Amedeo91 pushed a commit to Amedeo91/eve that referenced this pull request Aug 11, 2017

Amedeo91 pushed a commit to Amedeo91/eve that referenced this pull request Aug 11, 2017

Amedeo91 pushed a commit to Amedeo91/eve that referenced this pull request Aug 11, 2017

lexhung added a commit to lexhung/eve that referenced this pull request Nov 1, 2017

Merge branch 'master' of https://github.com/pyeve/eve into oplog_bug
* 'master' of https://github.com/pyeve/eve: (374 commits)
  Changelog for pyeve#1070
  use OrderedDict from backport_collections
  Minor changelog fixes for pyeve#1048
  Support Decimal type MongoDB
  Changelog: add reference to proper PR
  Changelog update for pyeve#1042
  Fix a serialization bug that randomly skips fields if "x_of" is encountered
  Amedeo Bussi
  Changelog for pyeve#1030
  pep/flake, and remove duplicate test
  documentation improvements and fixes
  Bulk delete
  MONGO_DBNAME can be now used along with MONGO_URI
  Vasilis Lolis
  typo
  Amedeo91
  Changelog for pyeve#1031
  Bulk Embedded document resolution
  Delete unnecessary code
  Fix insidious bug in tests.TestPost class
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment