Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Id__in fixes #70

Merged
merged 2 commits into from

2 participants

@baconz

Let me know your thoughts on these -- They address the three id__in bugs.

Seth Madison added some commits
Seth Madison Fixed id__in gremlin script so that it can take more than 250 nodes
NOTE: There isn't a test for this, because creating 250 nodes would
      slow the suite wayyy down. If we refactor a bit more, we could
      probably mock it, but you really need an integration test, since
      the issue stemmed from gremlin.
67e825b
Seth Madison Fix for type issues in id__in queries:
 * Now properly returns an empty queryset
 * Now properly returns a single node
d268f2a
@mhluongo

I was referring to in-graph type here, not REST client type. I'll add a more explanatory comment.

@mhluongo
Owner

This is... very ugly :) and perfect. Kudos, I had totally forgotten about _()!

@mhluongo mhluongo merged commit d268f2a into scholrly:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 12, 2012
  1. Fixed id__in gremlin script so that it can take more than 250 nodes

    Seth Madison authored
    NOTE: There isn't a test for this, because creating 250 nodes would
          slow the suite wayyy down. If we refactor a bit more, we could
          probably mock it, but you really need an integration test, since
          the issue stemmed from gremlin.
  2. Fix for type issues in id__in queries:

    Seth Madison authored
     * Now properly returns an empty queryset
     * Now properly returns a single node
This page is out of date. Refresh to see the latest.
View
12 neo4django/db/models/query.py
@@ -460,10 +460,18 @@ def execute(self, using):
id_set = reduce(and_, (set(c.value) for c in in_id_lookups))
if id_set:
ext = connections[using].extensions['GremlinPlugin']
- gremlin_script = 'g.v(%s)'
+ ## GREMLIN HACK ALERT: This is a workaround because g.v() can't
+ ## take more than 250 elements by itself.
+ ## According to gremlin devs, this is equiv
+ gremlin_script = 'list=[%s];res=[];list.each{res.add(g.v(it))};res._()'
gremlin_script %= ','.join(str(i) for i in id_set)
nodes = ext.execute_script(gremlin_script)
- #TODO also check type!!
+ ## TODO: HACKS: We don't know type coming out of neo4j-rest-client
+ # so we check it hackily here.
+ if nodes == u'null':
+ return
+ if hasattr(nodes, 'url'):
+ nodes = [nodes]
for node in nodes:
if all(matches_condition(node, c) for c in itertools.chain(indexed, unindexed)):
yield self.model_from_node(node)
View
6 neo4django/tests/nodequeryset_tests.py
@@ -282,6 +282,12 @@ def test_in_id():
eq_(len(people), 1)
eq_(people[0].id, uninteresting_man.id)
+ single_person = list(Person.objects.filter(id__in=(interesting_man.id,)))
+ eq_(len(single_person), 1)
+
+ no_people = list(Person.objects.filter(id__in=(1000,)))
+ eq_(len(no_people), 0)
+
def setup_teens():
setup_people()
make_people(['Tina', 'Rob', 'Tiny Tim'], [13, 15, 12])
Something went wrong with that request. Please try again.