Skip to content

Commit

Permalink
Don't fail if 'id' is missing from an object. (#464)
Browse files Browse the repository at this point in the history
The goal here is to give us the freedom to drop 'id' from FreeObject.
  • Loading branch information
msullivan authored and fantix committed Jan 9, 2024
1 parent fed7b24 commit be2de71
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
12 changes: 4 additions & 8 deletions edgedb/datatypes/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ EdgeObject_New(PyObject *desc)
return NULL;
}

if (EdgeRecordDesc_IDPos(desc) < 0) {
PyErr_SetString(
PyExc_ValueError,
"Cannot create Object without 'id' field");
return NULL;
}

Py_ssize_t size = EdgeRecordDesc_GetSize(desc);

if (size > EDGE_MAX_TUPLE_SIZE) {
Expand Down Expand Up @@ -137,7 +130,10 @@ EdgeObject_GetID(PyObject *ob)
assert(EdgeObject_Check(ob));
EdgeObject *o = (EdgeObject *)ob;
Py_ssize_t i = EdgeRecordDesc_IDPos(o->desc);
if (i < 0 || i >= Py_SIZE(o)) {
if (i < 0) {
Py_RETURN_NONE;
}
if (i >= Py_SIZE(o)) {
PyErr_BadInternalCall();
return NULL;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/datatypes/test_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,8 @@ def test_object_5(self):
lb='link-property',
c='property'
)
with self.assertRaisesRegex(ValueError, "without 'id' field"):
f(1, 2, 3)
x = f(1, 2, 3)
self.assertFalse(hasattr(x, 'id'))

def test_object_6(self):
User = private.create_object_factory(
Expand Down

0 comments on commit be2de71

Please sign in to comment.