neomodel icon indicating copy to clipboard operation
neomodel copied to clipboard

Create_or_update and get_or_update not working as expected

Open yorgomoubayed opened this issue 4 years ago • 7 comments
trafficstars

Dear community,

I am working on a project that involves Neomodel, Neo4j and Django. When I use the create_or_update and get_or_update functions, the code runs without any errors but does not create/save the data in the database. Here is how my code is built:

******Connection to db configuration: (in the settings.py file of Django): ...

NEOMODEL_NEO4J_BOLT_URL = os.environ.get('NEO4J_BOLT_URL','bolt://neo4j:neo4@localhost:7687')

******Data model of the an example node I want to create:

#Python imports from uuid import uuid4

#Third-party imports from neomodel import StructuredNode, StringProperty, IntegerProperty, UniqueIdProperty, RelationshipTo, DateProperty

#Models imports from api.models.dpstep_model import DPStep from api.models.storagehost_model import StorageHost from api.models.construct_model import Construct

class Dataset(StructuredNode):

"""
Defines node properties and relationships
Provides data serializer
"""

# Properties
uuid=StringProperty(unique_index=True, default=uuid4)
fileTemplateName=StringProperty()
userUuid=StringProperty()
crystalUuid=StringProperty()
currentPath=StringProperty(max_length=500)
generationPath=StringProperty(max_length=500)
blStartingDate=StringProperty()
beamlineName=StringProperty()
facilityName=StringProperty()

# Relationships
input_of=RelationshipTo(DPStep, 'INPUT')
stored=RelationshipTo(StorageHost, 'STORED')
belongs=RelationshipTo(Construct, 'BELONGS')

@property
def serialize(self):

	"""
	Serializer for node properties
	"""
	
	return {
	'dataset_node_properties': {
	'uuid': self.uuid,
	'fileTemplateName': self.fileTemplateName,
	'userUuid': self.userUuid,
	'crystalUuid': self.crystalUuid,
	'currentPath': self.currentPath,
	'generationPath': self.generationPath,
	'blStartingDate': self.blStartingDate,
	'beamlineName': self.beamlineName,
	'facilityName': self.facilityName,
	},
	}

******Code that stores the data:

@csrf_exempt def storeInput(request):

"""
Parse JSON data and call store functions for each model
"""

if request.method=='POST':
    json_data=json.loads(request.body)
    
    json_data_dataset=json_data['dataset']

    try:
        # Register nodes
        storeParseDataset(json_data_dataset)

        return JsonResponse({"Status": "INPUT SUCCESSFULLY REGISTERED"})

    except :
        return JsonResponse({"Status":"ERROR OCCURRED"}, safe=False)

@csrf_exempt def storeParseDataset(data):

"""
Creates nodes for each dataset with relative properties
"""

try:
    dataset=Dataset.get_or_create(uuid=data['uuid'],
        userUuid=data['userUuid'], 
        crystalUuid=data['crystalUuid'],
        currentPath=data['currentPath'],
        generationPath=data['generationPath'],
        fileTemplateName=data['fileTemplateName'],
        blStartingDate=data['blStartingDate'],
        beamlineName=data['beamlineName'],
        facilityName=data['facilityName'])

    return dataset.serialize

except:
    print(sys.exc_info()[0])
    return ({"STATUS": "ERROR OCCURRED WHILE REGISTERING DATASET"})

******JSON data sent to API via Postman:

{ "dataset": { "uuid": "ec2ae6be-b290-4836-8fd5-92bcc6180a95", "fileTemplateName": "chPAP-PAP_CD028443_C4-1_Z381421864_w1_1_", "userUuid": "bc7613ad-d407-4f54-928a-9ca570b1f636", "crystalUuid": "747d0196-6ebd-4dff-b19b-dd2b8ad82d25", "currentPath": "/crimsXdata/CRIMS-ARCHITECTURE/IMAGES/marquez/2021/20210128_id23eh2/P-43782/X-35442/D-3867/", "generationPath": "/crimsXdata/CRIMS-ARCHITECTURE/IMPORT/DATASETS/chPAP/20210128_id23eh2/chPAP/chPAP-PAP_CD028443_C4-1_Z381421864", "blStartingDate": 20210128, "beamlineName": "ID23eh2", "facilityName": "ESRF" } }

Thank you for any help, Please do tell if any information is missing!

yorgomoubayed avatar May 05 '21 07:05 yorgomoubayed

Hi again! Any news regarding the issue?

yorgomoubayed avatar Jun 29 '21 09:06 yorgomoubayed

hi @yorgomoubayed, looking into this net week (week of July 28)

whatSocks avatar Jul 02 '21 14:07 whatSocks

@yorgomoubayed if you have a repo you can share with us it might speed things up (ok if not)

whatSocks avatar Jul 02 '21 14:07 whatSocks

Hi again! Any news regarding the issue?

yorgomoubayed avatar Jul 28 '21 12:07 yorgomoubayed

Hi again! Please, any updates?

yorgomoubayed avatar Aug 24 '21 09:08 yorgomoubayed

Is it possible to access the source code of these two functions?

yorgomoubayed avatar Aug 24 '21 09:08 yorgomoubayed

It's right here https://github.com/neo4j-contrib/neomodel/blob/bfeae3e10498006dc0aae6bab2885a3c0f194dc3/neomodel/core.py#L370

whatSocks avatar Aug 24 '21 13:08 whatSocks