Skip to content
This repository has been archived by the owner on Jan 13, 2023. It is now read-only.

__unset_gj_flag_sub_field has sometimes raises error. #263

Open
reversetracker opened this issue Aug 25, 2020 · 1 comment
Open

__unset_gj_flag_sub_field has sometimes raises error. #263

reversetracker opened this issue Aug 25, 2020 · 1 comment

Comments

@reversetracker
Copy link

reversetracker commented Aug 25, 2020

Describe the bug
A clear and concise description of what the bug is.

The document.py file has a function named "__unset_gj_flag_sub_field"
it sometimes ( not all times ) raises error even the same query usually works but very sometimes.

the exception log is as below.

File "/home/yongwoo/.conda/envs/pingme/lib/python3.6/site-packages/mongoengine_goodjson/document.py", line 155, in unset_flag
   cur_depth_attr = getattr(fld, "$$cur_depth$$")
AttributeError: 'StringField' object has no attribute '$$cur_depth$$'

So here is my fixed code and it works fine again but I never understand how come it happens.

def __unset_gj_flag_sub_field(self, name, fld, cur_depth):
    """Remove current depth to subfield."""
    # def unset_flag(fld, depth_lv):
    #     setattr(fld, "$$cur_depth$$", depth_lv - 1)
    #     cur_depth_attr = getattr(fld, "$$cur_depth$$")
    #     if (not isinstance(cur_depth_attr, int)) or cur_depth_attr < 0:
    #         delattr(fld, "$$cur_depth$$")
    
    def unset_flag(fld, depth_lv):
        __cur_depth = depth_lv - 1
        if isinstance(__cur_depth, int) and __cur_depth >= 0:
            setattr(fld, "$$cur_depth$$", __cur_depth)

    self.__apply_element(
        name, fld, cur_depth, unset_flag, "end_goodjson"
    )

because you declared setattr(fld, "$$cur_depth$$", depth_lv - 1) so that getattr(fld, "$$cur_depth$$") must always have $$cur_depth$$ property but as you see the error log above it raises..

To Reproduce
Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

@reversetracker
Copy link
Author

if you find out why it happens, please let me know

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

No branches or pull requests

1 participant