Code Monkey home page Code Monkey logo

Comments (5)

mbbfyb avatar mbbfyb commented on July 18, 2024

Given that that last bit of code doesn't actually work, I tried something similar to:

class CustomId(properties.IdProperty, abc.DataType):
    def validate(self, val):
        if val is not None:
            try:
                return str(val)
            except ValueError as e:
                raise exception.ValidationError(
                    'Not a valid string: {}'.format(val)) from e
    def to_db(self, val=None):
        return super(CustomId, self).to_db(val=val)
    def to_ogm(self, val):
        return super(CustomId, self).to_ogm(val)

class Person(goblin.Vertex):
    id = goblin.Property(CustomId(data_type=goblin.String), default='abc123')

but I am really just grasping at straws here.

from goblin.

davebshow avatar davebshow commented on July 18, 2024

Well, as far as the goblin.Element interface is concerned, all instantiated Goblin elements already have an id property:

In [1]: from goblin import Vertex

In [2]: class Person(Vertex): pass

In [3]: p = Person()

In [4]: p.id = 1

In [5]: p.id
Out[5]: 1

Goblin currently doesn't support custom id data types. It possibly could in the future. May I ask why you need this functionality? What provider are you working with? Typically they will handle element ids...

from goblin.

mbbfyb avatar mbbfyb commented on July 18, 2024

That makes sense, thanks for the response.

My use case is that I have objects with a uid that I was hoping to use as the authoritative vertex/edge identifier to keep things consistent across the platform. The same uid in my graph db corresponds to other things in different data stores (like Mysql, AWS S3 key, etc), and I was just trying to keep things the same.

As an easy solution, I can create my own custom property uid and map it to that, but it just wont match my other datastores in terms of the authoritative identifier of the vertex or edge.

I am working with Amazon Neptune which returns a random uuid when you create a vertex or edge, so I was trying to control that. Running a simple create vertex function sets the id of the object to something similar to

>>> leif.id
'acb0d299-68c3-2687-5cf8-3bc9edf99280'

I am not running the latest goblin due to Neptune's limitations if that makes a difference.

Here are my relevant pip packages:

aiogremlin==3.2.4
goblin==2.0.0
gremlinpython==3.3.1

from goblin.

davebshow avatar davebshow commented on July 18, 2024

What if you simply set the id with your own uuid and then save per usual?

leif.id = 'myobjectsuuid'
session.add(leif)
await session.flush()

I ask because I truly don't know...

from goblin.

mbbfyb avatar mbbfyb commented on July 18, 2024

I thought it would be that easy originally, but it does not seem to be the case.

>>> import goblin
>>> import asyncio
>>> from goblin import Goblin
>>>
>>> class Person(goblin.Vertex):
...     car = goblin.VertexProperty(goblin.String)
...
>>> async def store_element(app, vertex1):
...     session = await app.session()
...     session.add(vertex1)
...     await session.flush()
...
>>> loop = asyncio.get_event_loop()
>>> app = loop.run_until_complete(Goblin.open(loop, hosts=["neptune_host"]))
>>> app.register(Person)
>>>
>>> p1 = Person()
>>> p1.id = "abc123"
>>> p1.id
'abc123'
>>>
>>> loop.run_until_complete(store_element(app, p1))
>>> print(p1.id)
0eb0d4ec-f29c-0fc8-d282-f69ad3575497

EDIT: The behavior is the same with or without setting the id to a goblin.String property, like shown in the original comment on this ticket.

from goblin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.