Code Monkey home page Code Monkey logo

boolean_parser's People

Contributors

charkins avatar havok2063 avatar linozen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

boolean_parser's Issues

SQLParser doesn't understand relationship field names.

Thank-you for your work on this package. I'm curious if its possible to have the parser understand relationship field names like the sister project marvin-sqlalchemy-boolean-search appears to?

I would use that, however it doesn't allow SQLAlchemy >= 1.4.

`bindparam` leads to erronously repeated clause elements

The bindparam function used to bind values when comparing strings with = or == leads to the following erroneous SQL queries being emitted to the database.

For example, the following clause

supporter_amount=10 and (zip=53* or zip=54*)

leads to the following SQL query (only WHERE clause is included):

...
WHERE person.supporter_amount = 10.0 
  AND (lower(person.zip) ILIKE '54%' 
  OR lower(person.zip) ILIKE '54%')

As you can see, the last element of the OR clause overwrites the first. This bug is fixed when removing the bindparam function in this code here.

ModuleNotFoundError: No module named 'sqlalchemy.ext.declarative.api'

Hi!

I get the above error when I try to import the parse function as indicated in the docs:

>>> from boolean_parser import parse

Traceback:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-25-9aac25771e6f> in <module>
----> 1 from boolean_parser.parsers import base

~\miniconda3\envs\hv38\lib\site-packages\boolean_parser\__init__.py in <module>
     14 from __future__ import print_function, division, absolute_import
     15 
---> 16 from boolean_parser.parsers import Parser
     17 from boolean_parser.parsers import SQLAParser
     18 

~\miniconda3\envs\hv38\lib\site-packages\boolean_parser\parsers\__init__.py in <module>
     14 from __future__ import print_function, division, absolute_import
     15 from .base import Parser
---> 16 from .sqla import SQLAParser
     17 

~\miniconda3\envs\hv38\lib\site-packages\boolean_parser\parsers\sqla.py in <module>
     14 from __future__ import print_function, division, absolute_import
     15 from boolean_parser.parsers import Parser
---> 16 from boolean_parser.mixins import SQLAMixin
     17 from boolean_parser.actions.clause import Condition
     18 from boolean_parser.actions.boolean import BaseBool, BoolNot, BoolAnd, BoolOr

~\miniconda3\envs\hv38\lib\site-packages\boolean_parser\mixins\__init__.py in <module>
----> 1 from boolean_parser.mixins.sqla import SQLAMixin

~\miniconda3\envs\hv38\lib\site-packages\boolean_parser\mixins\sqla.py in <module>
     16 import decimal
     17 from sqlalchemy import func, bindparam
---> 18 from sqlalchemy.ext.declarative.api import DeclarativeMeta
     19 from sqlalchemy.orm.util import AliasedClass
     20 from sqlalchemy.dialects import postgresql

ModuleNotFoundError: No module named 'sqlalchemy.ext.declarative.api'

boolean_parser() does not appear to be thread safe

Using boolean_parser to handle text parsing to convert into SQLAlchemy queries, in Flask application, I was occassionally getting the error:
TypeError: Condition.__init__() missing 1 required positional argument: 'data'
I checked through all of my code, to make sure everything was correctly formatting the input string. Everything I could find in my code was throughly vetted.
Then I thought since it was a multi threaded app, perhaps this issue laid in the parser itself. I presumed the parser would be creating a new instance of parser each time. It seems to be doing that using the "parse()" method to create the correct base parser.

However given the following code, it crashes almost immediately the same way:
`if name == 'main':

from boolean_parser import parse as boolean_parser
from multiprocessing.dummy import Pool

test_string ="(owner_id == 418f5230-365f-4867-9721-0bd498968932)"

test_list = [test_string for t in range(0, 1000)]

with Pool(5) as p:
    print(p.map(boolean_parser, test_list))

`
The multiprocessing.dummy class is the same as using the Threading class, just makes it easy to switch back and forth.
If you were to run the list through a standard map function, it would execute correctly. If you use just the multiprocessing module it also just works. I love the functionality of this package, and I can probably get a work around figured out, but would prefer to get this working. This happens in 1.4 and 1.5 beta.

AttributeError: 'SQLACondition' object has no attribute 'bindname'

Thanks for the great utility!

I frequently run into the error below when the code in mixins/sqla.py tries to run a .ilike( ... ). All the other operators work fine. Here is a full trace:

  File "/opt/bitnami/python/lib/python3.7/site-packages/boolean_parser/parsers/sqla.py", line 54, in filter
    for condition in self.conditions]
  File "/opt/bitnami/python/lib/python3.7/site-packages/boolean_parser/parsers/sqla.py", line 54, in <listcomp>
    for condition in self.conditions]
  File "/opt/bitnami/python/lib/python3.7/site-packages/boolean_parser/parsers/sqla.py", line 54, in filter
    for condition in self.conditions]
  File "/opt/bitnami/python/lib/python3.7/site-packages/boolean_parser/parsers/sqla.py", line 54, in <listcomp>
    for condition in self.conditions]
  File "/opt/bitnami/python/lib/python3.7/site-packages/boolean_parser/mixins/sqla.py", line 135, in filter
    condition = self._filter_one(model, field=field, condition=condition)
  File "/opt/bitnami/python/lib/python3.7/site-packages/boolean_parser/mixins/sqla.py", line 186, in _filter_one
    '%' + bindparam(self.bindname, value) + '%')
AttributeError: 'SQLACondition' object has no attribute 'bindname'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.