mogui / pyorient

Orientdb driver for python that uses the binary protocol.
Apache License 2.0
166 stars 127 forks source link

OGM: NULL fields not queried correctly #262

Open grahamjamesaddis opened 6 years ago

grahamjamesaddis commented 6 years ago

The query.py:build_wheres() function should use 'is', not '=', as an operator when the value passed is 'None'

In order to correct this issue I would do the following:

The following code snippet demonstrates the issue on the following environment:

pyOrient version : 1.5.5

python version : 3.6.3

OrientDB version : 2.2.31

from pyorient.ogm import Graph, Config, declarative
from pyorient.ogm.property import (String, Integer)
ogm_config = Config.from_url("localhost/ogm_test", "root", "root", initial_drop = True)
g = Graph(ogm_config)
Node = declarative.declarative_node()

class table_a(Node):
    element_plural = 'table_a'
    column_1 = String()
    column_2 = Integer()
g.create_all(Node.registry)

db_data = [
    {"column_1":"Test 1", "column_2" : 1},
    {"column_1":"Test 1"},
    {"column_1":"Test 2", "column_2" : 1},
    {"column_1":"Test 2", "column_2" : None},
    ]

for data in db_data:
    res = g.table_a.create(**data)

query_res = g.table_a.query(**db_data[0]).all()
print(len(query_res)) # expected 1 got 1 (db_data[0])

query_res = g.table_a.query(**db_data[1]).all()
print(len(query_res)) # expected 2 got 2 (db_data[0] and db_data[1])

query_res = g.table_a.query(**db_data[2]).all()
print(len(query_res)) # expected 1 got 1 (db_data[2])

query_res = g.table_a.query(**db_data[3]).all()
print(len(query_res)) # expected 1 got 0 ??????? I expected db_data[3]