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

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

Merged
merged 1 commit into from
Aug 9, 2017

Conversation

Raychee
Copy link

@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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
nicolaiarocci added a commit that referenced this pull request Aug 9, 2017
@nicolaiarocci
Copy link
Member

Thanks!

@Raychee Raychee deleted the dev/raychee branch August 9, 2017 09:49
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
* '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
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants