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

List key with embedded quote causes error #786

Closed
ghost opened this issue May 16, 2018 · 4 comments · Fixed by #792
Closed

List key with embedded quote causes error #786

ghost opened this issue May 16, 2018 · 4 comments · Fixed by #792
Assignees
Labels

Comments

@ghost
Copy link

ghost commented May 16, 2018

Current Behavior

The below code causes error

2018-05-16 12:37:10,585 - ydk - ERROR - Data is invalid according to the yang model. Error details: Unexpected character(s) 'c' ("c'][second='1233']").
---------------------------------------------------------------------------
YModelError                               Traceback (most recent call last)
<ipython-input-7-ee771e2b8880> in <module>()
----> 1 q=codec.encode(codec_p,r)

~/p/lib/python3.6/site-packages/ydk/errors/error_handler.py in helper(self, provider, entity, *args, **kwargs)
    110             err_msg = "'{0}' and '{1}' cannot be None".format(pname, ename)
    111             raise _YServiceError(error_msg=err_msg)
--> 112         return func(self, provider, entity, *args, **kwargs)
    113     return helper

~/p/lib/python3.6/site-packages/ydk/services/codec_service.py in encode(self, provider, entity_holder, pretty, subtree)
     76             return payload_list
     77         else:
---> 78             return self._encode(provider, entity_holder, pretty, subtree)
     79 
     80     def _encode(self, provider, entity, pretty, subtree):

~/p/lib/python3.6/site-packages/ydk/services/codec_service.py in _encode(self, provider, entity, pretty, subtree)
    108             result = codec_service.encode(data_node, provider.encoding, pretty)
    109             self.logger.debug("Performing encode operation, resulting in {}".format(result))
--> 110             return result
    111 
    112     @_check_argument

/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/contextlib.py in __exit__(self, type, value, traceback)
     97                 value = type()
     98             try:
---> 99                 self.gen.throw(type, value, traceback)
    100             except StopIteration as exc:
    101                 # Suppress StopIteration *unless* it's the same exception that

~/p/lib/python3.6/site-packages/ydk/errors/error_handler.py in handle_runtime_error()
     80     finally:
     81         if _exc:
---> 82             _raise(_exc)
     83 
     84 

~/p/lib/python3.6/site-packages/ydk/errors/error_handler.py in _raise(exc)
     52     """
     53     if sys.version_info >= (3,3):
---> 54         exec("raise exc from None")
     55     else:
     56         raise exc

~/p/lib/python3.6/site-packages/ydk/errors/error_handler.py in <module>()

YModelError:  Unexpected character(s) 'c' ("c'][second='1233']"). Path: 

Steps to Reproduce

Run the below script

Your Script

from ydk.models.ydktest.ydktest_sanity import Runner

r = Runner()
t = Runner.TwoKeyList()
t.first = "ab'c"
t.second = 1233
r.two_key_list.append(t)
crud.create(provider, r)
@ghost ghost added the bug label May 16, 2018
@ghost ghost mentioned this issue May 16, 2018
@ghost ghost closed this as completed in #787 May 16, 2018
ghost pushed a commit that referenced this issue May 16, 2018
@ghost ghost reopened this May 23, 2018
@ghost
Copy link
Author

ghost commented May 23, 2018

Problem also exists with embedded slash inside key value

ghost pushed a commit that referenced this issue May 23, 2018
This reverts commit a3c88be.
@ghost ghost closed this as completed in 3f87475 May 23, 2018
@ghost ghost reopened this May 23, 2018
@ghost ghost mentioned this issue May 25, 2018
@ghost ghost closed this as completed in #792 May 25, 2018
ghost pushed a commit that referenced this issue May 25, 2018
@ghost ghost reopened this Jun 5, 2018
@ghost ghost assigned ygorelik Jun 5, 2018
@ghost
Copy link
Author

ghost commented Jun 5, 2018

The below test case needs to be fixed:

def test_embedded_single_quote_list_key(self):

@ygorelik
Copy link
Collaborator

ygorelik commented Jun 7, 2018

Fixed the issue in C++, Python, and Go. The solution includes smart calculation of key tokens for segment_path values. By default the single quote symbol is used to enclose key value. But when the key value includes single quote characters, the double quotes characters are used to enclose key value.
Here example of a test in Python:
'''

def test_embedded_quotes_list_key(self):
    t1 = Runner.TwoKeyList()
    t1.first = "ab'c"
    t1.second = 1233
    t2 = Runner.TwoKeyList()
    t2.first = 'ab"c'
    t2.second = 3211
    r = Runner()
    r.two_key_list.extend(t1, t2)

    self.crud.create(self.ncc, r)

    runner_read = self.crud.read(self.ncc, Runner())
    self.assertEqual(r, runner_read)

    self.crud.delete(self.ncc, r)

'''

The solution changes affects YDK core and generated bundles code. The user API is not affected.

@ygorelik ygorelik closed this as completed Jun 7, 2018
@ghost ghost reopened this Jun 12, 2018
ygorelik pushed a commit to ygorelik/ydk-gen that referenced this issue Jun 12, 2018
@ygorelik
Copy link
Collaborator

Refactored code for Python API to avoid changes in generated bundle code. All tests passed.

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

Successfully merging a pull request may close this issue.

1 participant