espeed / bulbs

A Python persistence framework for graph databases like Neo4j, OrientDB and Titan.
http://bulbflow.org
Other
622 stars 83 forks source link

Dictionary() property doesn't work due to invalid hashmap conversion #145

Open chiffa opened 10 years ago

chiffa commented 10 years ago

When the Dictionary property is attached and used the following error arises:

SystemError: ({'status': '200', 'content-length': '110', 'content-type': 'application/json; charset=UTF-8', 'access-control-allow-origin': '*', 'server': 'Jetty(6.1.25)'}, '"java.lang.IllegalArgumentException: Unknown property type on: {nom=1, mnom=1}, class java.util.LinkedHashMap"')

espeed commented 10 years ago

Some DBs such as Neo4j don't allow properties to be dictionaries (only primitive arrays). In this case you can use the Bulbs Document type instead of Dictionary -- the Document type converts Python dicts to JSON string before writing to the DB, and it converts JSON strings back to Python dicts when read from the DB.

chiffa commented 10 years ago

Great, would you mind providing more info about the Document type? I couldn't find it in the usual property documentation location: http://bulbflow.com/docs/api/bulbs/property/#property

espeed commented 10 years ago

The online docs need to be updated. The Document Property is defined here:

And here's how it gets called when using the default JSON type system:

NOTE: The Document Property definition uses the JSON type system's to_document() method to convert a Python dict to a JSON string when saving to the database, but it uses the to_dictionary() method to convert the JSON string to a Python dict when reading from the database.

chiffa commented 10 years ago

Great, thanks. Would you mind adding it to doc in a future release?