2

I'm trying to query my Employee model with .cypher within my Django view. I've used this query elsewhere, so I know that part works.

query_string = "MATCH (n)-[r:REPORTS_TO|BRANCH_OF|OVERSEEN_BY]->() RETURN n, r"

query_results = Employee.cypher(
    self = Employee, 
    query = query_string, 
    params = None)

***   ERROR _pre_action_check() 
      missing 1 required positional argument: 'action'

This error points to line 204 here:

https://github.com/neo4j-contrib/neomodel/blob/master/neomodel/core.py


I've tried:

  • action=cypher
  • action='cypher'
  • self=neomodel
  • self=django-neomodel
  • self=cypher

Also, if I try to follow the documentation by defining the cypher call within the model and then calling it in the view... I still get the same error

https://neomodel.readthedocs.io/en/latest/cypher.html


UPDATE: full trace here https://i.stack.imgur.com/hPs3B.jpg

Kermit
  • 4,922
  • 4
  • 42
  • 74
  • 1
    It is a *positional* parameter. – Willem Van Onsem Jul 18 '18 at 16:37
  • hmm. so something to do with `results, columns = self.cypher` ? thought that looked strange in the documentation – Kermit Jul 18 '18 at 16:41
  • Can we see the entire Traceback? – JacobIRR Jul 18 '18 at 16:46
  • @JacobIRR updated with trace! – Kermit Jul 18 '18 at 16:50
  • @HashRocketSyntax Is Employee a Class object? It looks like it is reading your query string as the self argument because Employee isn't an instance. – Tezra Jul 18 '18 at 17:54
  • @Tezra Yes. Employee is a class in the model. – Kermit Jul 18 '18 at 18:08
  • 1
    Ok, so your query string is being read as the self argument, and it is still waiting for the query string. You need to create an instance of Employee to call .cypher on. I don't know how to help further, but sounds like @JacobIRR knows how to take it from here. (unless you know already how to create the instance object) – Tezra Jul 18 '18 at 18:10

1 Answers1

3

The fact that you're calling this method with three positional args seems wrong.

The method signature is:

def cypher(self, query, params=None):

-self is already provided by your Employee. prefix. (WRONG, see below)

-query should just be passed in as positional query_string argument

-params=None is simply passing the default value, which is useless.

Have you tried Employee.cypher(query_string) ?

Based on what Tezra said, you need an instance of Employee:

employee = Employee()

Then call employee.cypher(query_string)

JacobIRR
  • 8,545
  • 8
  • 39
  • 68
  • yes that was the first thing i tried. i can reply after lunch with the error it produces – Kermit Jul 18 '18 at 16:51
  • Sounds good - I'd like to see that error since it at least comes from using the method as expected. – JacobIRR Jul 18 '18 at 16:52
  • `cypher() missing 1 required positional argument: 'query'` in response to Employee.cypher(query_string) – Kermit Jul 18 '18 at 17:37
  • Can you share the full trace for that example? The only way I get `cypher() missing 1 required positional argument: 'query'` is to call `cypher` with no arguments at all. – JacobIRR Jul 18 '18 at 17:48
  • 3
    @JacobIRR It looks like Employee is the class, not the instance, so the query is being read as the self argument... I'm not familiar with the python driver so I don't know how to create an instance of self though (I'm guessing that is the asnwer). – Tezra Jul 18 '18 at 17:59
  • @Tezra @JacobIRR the instance did it! thank you! working on new error "Employee.cypher() attempted on unsaved node" which im pretty sure is because im using uid, not id attributes `if not hasattr(self, 'id'): raise ValueError("{}.{}() attempted on unsaved node".format( self.__class__.__name__, action))` – Kermit Jul 18 '18 at 21:06
  • merp. no it looks like they have id's too `'id': 68}>,` so maybe it's the instance. – Kermit Jul 18 '18 at 21:11
  • looks like Employee() is creating a new resource ` – Kermit Jul 18 '18 at 21:20