orientechnologies / pyorient

OrientDB driver for Python that uses the binary protocol.
Apache License 2.0
119 stars 38 forks source link

Writing bytes into OGM object throws an exception #40

Open FredPraca opened 4 years ago

FredPraca commented 4 years ago

Using the following class representation:

class Sensor(Node):
     name = String()
     zone = String()
     photo = Binary()

I'm able to create the schema in the database using the Node registry without any problem.

When trying to insert values using:

graph.create_vertex(Sensor,
       name = 'test',
       zone = 'z1',
       photo = bytes_read)

where _bytesread comes from

with open('/home/test/Images/test.png', 'rb') as f:
     bytes_read = f.read();

I got the following stacktrace

Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
  File "/home/test/.local/lib/python3.6/site-packages/pyorient/ogm/graph.py", line 546, in create_vertex
    to_unicode(self.create_vertex_command(vertex_cls, **kwargs)))[0]
  File "/home/test/.local/lib/python3.6/site-packages/pyorient/orient.py", line 463, in command
    .prepare(( QUERY_CMD, ) + args).send().fetch_response()
  File "/home/test/.local/lib/python3.6/site-packages/pyorient/messages/commands.py", line 144, in fetch_response
    super( CommandMessage, self ).fetch_response()
  File "/home/test/.local/lib/python3.6/site-packages/pyorient/messages/base.py", line 265, in fetch_response
    self._decode_all()
  File "/home/test/.local/lib/python3.6/site-packages/pyorient/messages/base.py", line 249, in _decode_all
    self._decode_header()
  File "/home/test/.local/lib/python3.6/site-packages/pyorient/messages/base.py", line 182, in _decode_header
    [ exception_message.decode( 'utf8' ) ]
pyorient.exceptions.PyOrientSQLParsingException: com.orientechnologies.orient.core.sql.OCommandSQLParsingException - Lexical error at line 1, column 57.  Encountered: "x" (120), after : "\'\\"
    DB name="test"
    Error Code="1"

I suspect the binary is not correctly encoded as in PropertyEncoder, I don't find ay case to serialize Binary object.

brucetony commented 3 years ago

I was able to patch the library to work with OrientDB 3.1+ and updated the README to give descriptions of how to connect to your database now. You can find my patched version here: https://github.com/brucetony/pyorient