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

OGM: NULL fields not queried correctly #262

Open
grahamjamesaddis opened this issue Jan 15, 2018 · 0 comments
Open

OGM: NULL fields not queried correctly #262

grahamjamesaddis opened this issue Jan 15, 2018 · 0 comments

Comments

@grahamjamesaddis
Copy link

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:

  • Extend property.py:PropertyEncoder with an 'encode_operator()' method e.g.:
    @staticmethod
    def encode_operator(value):
        if value:
            return ' = '
        else:
            return ' is '
  • Modify build_wheres() to include the call to 'encode_operator()' e.g.:
        kw_where = [u' and '.join(u'{0}{1}{2}'
            .format(PropertyEncoder.encode_name(k),
                    PropertyEncoder.encode_operator(v),
                    PropertyEncoder.encode_value(v))
                for k,v in kw_filters.items())] if kw_filters else []

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]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant