espeed / bulbs

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

get_unique/get_or_create #121

Closed mmarklar closed 10 years ago

mmarklar commented 10 years ago

Hi,

Using Titan, I tried following the documentation to get or create a vertex and am getting an error:

AttributeError: 'KeyIndex' object has no attribute 'get_unique'

I've created a model and added a proxy to it on the graph. This error shows up when I call graph.objectproxy.get_or_create(). I thought I had seen it in the source code but when I looked at my installed version its not there.

Am I doing something wrong or is this a case of the documentation and source getting out of sync?

Thanks

espeed commented 10 years ago

Here's the code for VertexProxy.get_or_create():

https://github.com/espeed/bulbs/blob/master/bulbs/element.py#L584

What database server are you using (Rexster, Neo4j Server, Titan Server, etc)?

And how did add the model...?

>>> from people import Person
>>> from bulbs.rexster import Graph
>>> g = Graph()
>>> g.add_proxy("people", Person)
>>> james1 = g.people.create(name="James")
>>> james2 = g.people.get_or_create(name, "James")
>>> assert james1 == james2
mmarklar commented 10 years ago

Thanks for the prompt reply!

I am using Titan Server. My code looks like this:

from models import User
from bulbs.titan import Graph, Config

titanConfig = Config("host address")
graph = Graph(titanConfig)

graph.add_proxy("user", User)
user = graph.user.get_or_create(username, "emailaddress")
espeed commented 10 years ago

The get_unique() method was missing from bulbs.titan.index -- I added it back and pushed the changes to GitHub and PyPi:

https://github.com/espeed/bulbs/blob/master/bulbs/titan/index.py#L274

However, I didn't have time to fire up Titan and test it so please let me know how it works.

espeed commented 10 years ago

Did this resolve the issue?

espeed commented 10 years ago

Presume fixed.