0
votes

I think there is a problem when creating records in a graph using transactions. The vertices created during the transaction are always stored in the cluster #3, when I check on studio webapp the vertex created in the tx has class 'Unknown'

Here is the code:

client = pyorient.OrientDB("localhost", 2424)
client.connect("xxx", "xxx")
client.db_open("admin", "admin")

people_cluster = client.command("create class People extends V")
client.command("create vertex People content {'name': 'dummy', 'age': 21}")

attrs = {'@People': {'name': 'another_me', 'age': 31}}
res = client.record_create(people_cluster[0], attrs)

attrs2 = {'@People': {'name': 'me', 'age': 30}}
create_rec_cmd = ( client.get_message(pyorient.RECORD_CREATE) ).prepare((people_cluster[0], attrs2))

tx = tx.commit()
tx.begin()
tx.attach(create_rec_cmd)
tx.commit()

# This returns 'dummy' and 'another_me', but the people created in the tx is not present
res = client.command("select from People")

print(res[0]) => {'@People':{'age': 21, 'name': 'dummy', 'version':2,'rid':'#13:0'}
print(res[1]) => {'@People':{'age': 31, 'name': 'another_me'},'version':1,'rid':'#13:1'}

# The ones created in the transaction are found in the cluster #3, but with no class
print(client.command("select from #3:0")[0]) => {{'name': 'me', 'age': 30},'version':1,'rid':'#3:0'}

I have activated the debug option in the xml config, and the log doesn't give much information:

2015-08-16 17:59:46:992 INFO {db=test} /192.168.10.1:41317 - Read byte: 60 [OChannelBinaryServer]

2015-08-16 17:59:46:994 INFO {db=test} /192.168.10.1:41317 - Reading int (4 bytes)... [OChannelBinaryServer]

2015-08-16 17:59:46:995 INFO {db=test} /192.168.10.1:41317 - Read int: 6 [OChannelBinaryServer]

2015-08-16 17:59:47:000 INFO {db=test} /192.168.10.1:41317 - Reading int (4 bytes)... [OChannelBinaryServer]

2015-08-16 17:59:47:002 INFO {db=test} /192.168.10.1:41317 - Read int: 2113677732 [OChannelBinaryServer]

2015-08-16 17:59:47:003 INFO {db=test} /192.168.10.1:41317 - Reading byte (1 byte)... [OChannelBinaryServer]

2015-08-16 17:59:47:004 INFO {db=test} /192.168.10.1:41317 - Read byte: 1 [OChannelBinaryServer]

2015-08-16 17:59:47:005 INFO {db=test} /192.168.10.1:41317 - Reading byte (1 byte)... [OChannelBinaryServer]

2015-08-16 17:59:47:006 INFO {db=test} /192.168.10.1:41317 - Read byte: 1 [OChannelBinaryServer]

2015-08-16 17:59:47:006 INFO {db=test} /192.168.10.1:41317 - Reading byte (1 byte)... [OChannelBinaryServer]

2015-08-16 17:59:47:007 INFO {db=test} /192.168.10.1:41317 - Read byte: 3 [OChannelBinaryServer]

2015-08-16 17:59:47:007 INFO {db=test} /192.168.10.1:41317 - Reading short (2 bytes)... [OChannelBinaryServer]

2015-08-16 17:59:47:007 INFO {db=test} /192.168.10.1:41317 - Read short: -1 [OChannelBinaryServer]

2015-08-16 17:59:47:008 INFO {db=test} /192.168.10.1:41317 - Reading long (8 bytes)... [OChannelBinaryServer]

2015-08-16 17:59:47:008 INFO {db=test} /192.168.10.1:41317 - Read long: -2 [OChannelBinaryServer]

2015-08-16 17:59:47:009 INFO {db=test} /192.168.10.1:41317 - Reading byte (1 byte)... [OChannelBinaryServer]

2015-08-16 17:59:47:009 INFO {db=test} /192.168.10.1:41317 - Read byte: 100 [OChannelBinaryServer]

2015-08-16 17:59:47:010 INFO {db=test} /192.168.10.1:41317 - Reading chunk of bytes. Reading chunk length as int (4 bytes)... [OChannelBinaryServer]

2015-08-16 17:59:47:010 INFO {db=test} /192.168.10.1:41317 - Read chunk lenght: 18 [OChannelBinaryServer]

2015-08-16 17:59:47:011 INFO {db=test} /192.168.10.1:41317 - Reading 18 bytes... [OChannelBinaryServer]

2015-08-16 17:59:47:011 INFO {db=test} /192.168.10.1:41317 - Read 18 bytes: age:30,name:"me" [OChannelBinaryServer]

2015-08-16 17:59:47:016 INFO {db=test} /192.168.10.1:41317 - Reading byte (1 byte)... [OChannelBinaryServer]

2015-08-16 17:59:47:017 INFO {db=test} /192.168.10.1:41317 - Read byte: 0 [OChannelBinaryServer]

2015-08-16 17:59:47:017 INFO {db=test} /192.168.10.1:41317 - Reading chunk of bytes. Reading chunk length as int (4 bytes)... [OChannelBinaryServer]

1

1 Answers

0
votes

The pyorient docs have the following example (with a few lines removed for clarity)...

tx = client.tx_commit()
tx.begin()

# create a new record
rec1 = { 'accommodation': 'home', 'work': 'some work', 'holiday': 'surf' }
rec_position1 = client.record_create( -1, rec1 )

tx.attach( rec_position1 )

The source code for record_create is as follows...

def record_create(self, *args):
return self.get_message("RecordCreateMessage") \
    .prepare(args).send().fetch_response()

Your code is only running the get_message and the prepare functions, but not send and fetch_response. I suspect this is where your problem lies.