mogui/pyorient

DEFAULT property values in embedded types returned incorrectly

Closed this issue · 1 comments

I was able to reproduce this bug in both OrientDB 2.2.7 and in OrientDB 2.1.16. To reproduce, first create a new database and fill it as such:

create class V1 extends V
create class data
create property data.normal Boolean
alter property data.normal default 0
create property V1.info embeddedmap data
create vertex V1 set info={'foo': {}}

Note that because of the default value of the embedded type, the info field has the following data, as shown by OrientDB Studio: {"foo":{"@type":"d","@version":0,"@class":"data","normal":false}}

Then, fire up your favorite Python REPL and use pyorient:

from pyorient.ogm import *
from pyorient.ogm.declarative import *

base_node = declarative_node()
base_relationship = declarative_relationship()

g = Graph(Config.from_url('test_db', 'admin', 'admin'))
g.include(g.build_mapping(base_node, base_relationship, auto_plural=True))

x = g.V1.query().one()

Then, peek at the data in x._props and you'll see the following {'info': {'foo': {'normal': 'false)}', 'o_class': 'data'}}}. Since normal is a boolean field, we expected to find the Python boolean value False. Instead, its value is the string 'false)}'.

The extra "junk" data in the optional field is dependent on what other fields are defined on the embedded class -- it's frequent that other field names get included, which is why I think it's a protocol mis-parsing issue. However, I'm not sure if this is a bug on the side of OrientDB's binary protocol implementation (e.g. it doesn't send a correctly-terminated string) or on the side of pyorient's parsing of that protocol.

I was able to reproduce this bug in OrientDB 2.1.16 as well, and updated the issue title and content accordingly.