question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

First of all, amazing work putting this library together, it is super helpful!

I’m trying to create an UNWIND statement passing it a list of items to unwind. My goal is to have something like this:

UNWIND $batch AS row where $batch is a list of dicts => [{…}, {…}, {…}]

Unfortunately I’m not able to set a list as a valid parameter (unhashable type list). This is my attempt:

batch = [dict(city='hamburg', members=300), dict(city='berlin', members=900), dict(city='koln', members=190)]

unwind_q = Pypher()
batch_p = Param(name='batch', value=batch)
unwind_q.unwind(batch_p).alias('row')

Initially it does not crash but it does crash when trying to see the actual cypher query with the following error:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-156-1bd1789a4c0a> in <module>
      6 unwind_q.unwind(batch_p).alias('row')
      7 
----> 8 cprint(unwind_q)

<ipython-input-67-e7bd6c8eb90e> in cprint(pypher)
     27 
     28 def cprint(pypher):
---> 29     c = str(pypher)
     30     p = pypher.bound_params
     31     print('Cypher:')

/usr/local/lib/python3.7/site-packages/pypher/builder.py in __str__(self)
    323 
    324     def __str__(self):
--> 325         return self.__unicode__()
    326 
    327     def __unicode__(self):

/usr/local/lib/python3.7/site-packages/pypher/builder.py in __unicode__(self)
    353                 suff = ' '
    354 
--> 355             part = '{}{}{}'.format(pre, str(token), suff)
    356             tokens.append(part)
    357 

/usr/local/lib/python3.7/site-packages/pypher/builder.py in __str__(self)
    323 
    324     def __str__(self):
--> 325         return self.__unicode__()
    326 
    327     def __unicode__(self):

/usr/local/lib/python3.7/site-packages/pypher/builder.py in __unicode__(self)
    636                     arg.parent = self.parent
    637                 elif isinstance(arg, Param):
--> 638                     self.bind_param(arg)
    639                     arg = arg.placeholder
    640 

/usr/local/lib/python3.7/site-packages/pypher/builder.py in bind_param(self, value, name)
    294     def bind_param(self, value, name=None):
    295         self.params.pypher = self
--> 296         return self.params.bind_param(value=value, name=name)
    297 
    298     def __getattr__(self, attr):

/usr/local/lib/python3.7/site-packages/pypher/builder.py in bind_param(self, value, name)
    196                     name = k
    197                     break
--> 198         elif bind and value in self._bound_params.keys():
    199             for k, v in self._bound_params.items():
    200                 if k == value:

TypeError: unhashable type: 'list'

Any ideas on how could I pass a list to UNWIND?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
emehrkaycommented, Nov 21, 2019

Nice. I actually wrote a comment on using Raw, but didn’t hit submit. I was wondering if you could just use __.row.City but that would produce \'row.`City`` and I don’t think that would work for you.

Glad it worked out

0reactions
quiincommented, Nov 21, 2019

Thanks for helping me, really appreciate it! Closing this issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

$unwind (aggregation) — MongoDB Manual
Deconstructs an array field from the input documents to output a document for each element. Each output document is the input document with...
Read more >
The best 81 unwind sentence examples
Unwind sentence example · He'd messed around with Jenn only a few hours earlier and already felt the need to unwind again. ·...
Read more >
How To Use MongoDB $unwind – BMC Software | Blogs
You will see this as I walk you through this example. MongoDB $unwind transforms complex documents into simpler documents, which increase ...
Read more >
Examples of 'unwind' in a sentence - Collins Dictionary
Examples from the Collins Corpus · It's the perfect place to unwind after a day 's exploring. · We need time to relax...
Read more >
Examples of unwind - Cambridge Dictionary
Examples of unwind · As the spring unwinds, it turns a generator. · The second stretching mode is accompanied by unwinding. · As...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found