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

yadcf_range_number search inf not working - mysql? #121

Open
louking opened this issue Jul 9, 2019 · 1 comment
Open

yadcf_range_number search inf not working - mysql? #121

louking opened this issue Jul 9, 2019 · 1 comment

Comments

@louking
Copy link
Collaborator

louking commented Jul 9, 2019

When I do a yadcf_range_number search with the filter only specifying one side, an error is generated. I am not sure if this is an issue with mysql or with python 2.7 use of float('inf'). The response to the browser has

json.error
"(_mysql_exceptions.OperationalError) (1054, "Unknown column 'inf' in 'where clause'")
[SQL: SELECT count(*) AS count_1 
FROM (SELECT race.date AS race_date 
FROM series, raceresult INNER JOIN runner ON runner.id = raceresult.runnerid INNER JOIN race ON race.id = raceresult.raceid INNER JOIN location ON location.id = race.locationid 
WHERE raceresult.club_id = %s AND race.date BETWEEN %s AND %s AND lower(raceresult.runnerid) LIKE lower(%s) AND series.name LIKE %s AND round(race.distance, %s) BETWEEN %s AND %s) AS anon_1]
[parameters: (2L, datetime.datetime(2016, 7, 1, 0, 0), datetime.datetime(2019, 7, 9, 0, 0), '%502%', 'grandprix', 2, 5.0, inf)]
(Background on this error at: http://sqlalche.me/e/e3q8)"

so seems float('inf') at

v_to = float(v_to) if v_to != '' else float('inf')
results with inf as the second parameter for the between clause of the query.

I see this is tested at

def test_yadcf_range_number_gt(session):
so not sure if this is an issue because I'm using python 2.7 or if mysql doesn't support inf.

@louking
Copy link
Collaborator Author

louking commented Jul 9, 2019

This monkey patch seems to take care of the problem for me. Not sure the best term to use rather than float('inf'). sys.maxsize seemed to be recommended in some of the searches I've done, and is portable to python 3. I also tried sys.float_info.max but this caused error in mysql.

# monkey patch yadcf_range_number search method
def alt_yadcf_range_number(expr, value):
    v_from, v_to = value.split('-yadcf_delim-')
    v_from = float(v_from) if v_from != '' else -sys.maxsize+1 # was float('-inf')
    v_to = float(v_to) if v_to != '' else sys.maxsize # was float('inf')
    # logger.debug('yadcf_range_number: between %f and %f', v_from, v_to)
    return expr.between(v_from, v_to)
from datatables.search_methods import SEARCH_METHODS
SEARCH_METHODS['yadcf_range_number'] = alt_yadcf_range_number

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