neo4j-contrib / neomodel

An Object Graph Mapper (OGM) for the Neo4j graph database.
https://neomodel.readthedocs.io
MIT License
939 stars 231 forks source link

fix creating a semi structured node with optional values omitted #699

Closed EricAtORS closed 1 year ago

EricAtORS commented 1 year ago

I was trying to create a semi structured node with only the required values present and it would fail. This PR fixes it. I've added a test to demonstrate the use case I have.

aanastasiou commented 1 year ago

Thanks @EricAtORS , will have a look shortly. Just out of curiosity, can you please post the minimal example that was failing?

EricAtORS commented 1 year ago

Hi @aanastasiou

Of course. I've added it to the test suite. This is the minimal reproducible example:

from neomodel import IntegerProperty, StringProperty
from neomodel.contrib import SemiStructuredNode

class UserProf(SemiStructuredNode):
    email = StringProperty(unique_index=True, required=True)
    age = IntegerProperty(index=True)

def test_to_save_to_model_with_required_only():
    u = UserProf(email="dummy@test.com")
    assert u.save()
aanastasiou commented 1 year ago

@EricAtORS Can you please describe the error you were getting? (I am getting an error indeed, but I would like us to confirm that we are talking about the same thing).

@EricAtORS Disregard please, I see what the problem was now.

EricAtORS commented 1 year ago

@aanastasiou I hadn't seen the udpated, but just in case you still need it:

  File "...\lib\site-packages\neomodel\contrib\semi_structured.py", line 61, in deflate
    raise DeflateConflict(cls, key, deflated[key], obj.id)
KeyError: 'description'

Thanks for the udpate

codecov[bot] commented 1 year ago

Codecov Report

Merging #699 (e8c1b2f) into rc/5.1.0 (f07b331) will increase coverage by 0.10%. The diff coverage is 100.00%.

@@             Coverage Diff              @@
##           rc/5.1.0     #699      +/-   ##
============================================
+ Coverage     89.46%   89.56%   +0.10%     
============================================
  Files            15       15              
  Lines          1994     1994              
============================================
+ Hits           1784     1786       +2     
+ Misses          210      208       -2     
Impacted Files Coverage Δ
neomodel/contrib/semi_structured.py 85.29% <100.00%> (+5.88%) :arrow_up:
EricAtORS commented 1 year ago

@mariusconjeaud Thank you!