threefoldtecharchive / jumpscaleX_archived

Apache License 2.0
1 stars 6 forks source link

incorrect object returned by model.get #693

Closed xmonader closed 5 years ago

xmonader commented 5 years ago

having multiple schemas and multiple objects from these schema

ipdb> print(schema)                                                                                                                                                                     
proj.human
ipdb> model                                                                                                                                                                             
model:proj.human

ipdb> model.new()._schema                                                                                                                                                               
## SCHEMA: proj.human

prop:name                      string
prop:phone                     string

ipdb> model.get(1)._schema                                                                                                                                                              
## SCHEMA: proj.person

prop:name                      string
prop:email                     string

calling new gives the correct objct from schema proj.human while calling get(1) gets another object from another schema!

schemas


j.data.schema.add_from_text("""
@url = proj.email
addr* = "" (S)
""")
j.data.schema.add_from_text("""
@url = proj.person
name* = "" (S)
email* = "" !proj.email
""")

j.data.schema.add_from_text("""
@url = proj.os
name* = "" (S)
""")

j.data.schema.add_from_text("""
@url = proj.phone
model* = "" (S)
os* = "" !proj.os
""")

j.data.schema.add_from_text("""
@url = proj.lang
name* = ""
""")

j.data.schema.add_from_text("""
@url = proj.human
name* = "" (S)
favnums = (LS)
langs = (LO) !proj.lang
phone* = "" !proj.phone
""")
rkhamis commented 5 years ago

I think in this case what should happen is that error is raised when the id does not correspond to the model.

Otherwise it just doesn't make sense and instead you should use get_by_name

xmonader commented 5 years ago

@rkhamis problem is get on model actually delegates the call to model.bcdb.get which returns the object by auto incremented creation id

get on model should return the object with respect to the model itself.

does get_by_name assume that there's name property on every model? or is created implicitly?

BolaNasr commented 5 years ago

Fixed it by Raise error if we didn't have this id in our object model image

john-kheir commented 5 years ago

Verified

Verification steps

1- Create any schema schema_text = """@url = proj.human name* = test-name """ 2- bcdb = j.data.bcdb.get("test") 3- model = bcdb.model_get_by_schema(schema_text) 4- z = model.new(), then z.save() 5- model.get(1) --> this will get the model you just created 6- model.get(2) this will throw an error since model with id=2 is not there

Branch: development commit: https://github.com/threefoldtech/jumpscaleX/commit/aec05fa188829dcc01f8d1fc1a69fe8c24a5f600