Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create_or_update and get_or_update not working as expected #558

Open
yorgomoubayed opened this issue May 5, 2021 · 7 comments
Open

Create_or_update and get_or_update not working as expected #558

yorgomoubayed opened this issue May 5, 2021 · 7 comments

Comments

@yorgomoubayed
Copy link

yorgomoubayed commented May 5, 2021

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
Copy link
Author

Hi again! Any news regarding the issue?

@whatSocks
Copy link
Collaborator

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

@whatSocks
Copy link
Collaborator

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

@yorgomoubayed
Copy link
Author

Hi again! Any news regarding the issue?

@yorgomoubayed
Copy link
Author

Hi again! Please, any updates?

@yorgomoubayed
Copy link
Author

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

@whatSocks
Copy link
Collaborator

It's right here

def create_or_update(cls, *props, **kwargs):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

2 participants