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

Avoid DB error due to invalid integer value while adding object to the search index #70

Merged
merged 1 commit into from
Jan 9, 2018

Conversation

pkamps
Copy link
Member

@pkamps pkamps commented Sep 18, 2017

You run into a DB error if you use the default search engine (not solr) and an attribute happens to contain a number that is bigger than the maximal integer size allowed by the DB.

How to reproduce the issue:

  1. Use a content class that has a ezstring (text) attribute
  2. Create a new node
  3. In the text field type in following content: 3147483647
  4. Send the new node for publishing

It will result in a fatal error, showing a DB transaction error.

That's due to the fact that kernel/search/plugins/ezsearchengine/ezsearchengine.php tries to save an integer value in the DB table ezsearch_object_word_link column integer_value. That PHP file is checking if the given attribute value is a numeric value:

https://github.com/mugoweb/ezpublish-legacy/blob/master/kernel/search/plugins/ezsearchengine/ezsearchengine.php#L97

If that's the case, it will try to store the integer value but it does not check if the value can be saved to the DB due to the limitation (max/min value) of a integer column in the DB.

This patch is limiting the integer value to the maximal/minimal value the DB can handle. Therefore it will not run into a SQL error (transaction error message).

That issue is known - here is the issue report:
https://jira.ez.no/browse/EZP-26209?jql=text%20~%20%22Out%20of%20range%20value%20for%20column%20%27integer_value%27%22

There is even a pull request:
ezsystems#1268

I decided not to use the pull request because it's not checking for the min value. Also, the information about the max/min integer value should be set in the DB API classes and not in
https://github.com/mugoweb/ezpublish-legacy/blob/master/kernel/search/plugins/ezsearchengine/ezsearchengine.php

References:
https://dev.mysql.com/doc/refman/5.7/en/integer-types.html
https://www.postgresql.org/docs/9.1/static/datatype-numeric.html

@thiagocamposviana
Copy link

I tried to reproduce the issue with MariaDB and MySQL 5.5.54 and I couldn't, good news is that with the patch it works exactly the same as without, so I am not sure here, feel free to merge this into master just in case, maybe this should affect older versions of mysql?

@pkamps
Copy link
Member Author

pkamps commented Nov 12, 2017

Looks like there is a "strict" mode in mysql:

https://dev.mysql.com/doc/refman/5.7/en/out-of-range-and-overflow.html
https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sql-mode-strict

Depending on this setting mysql will through an error or will cap the given value to its max/min value.

@pkamps
Copy link
Member Author

pkamps commented Nov 15, 2017

Can you please check if you DB is running in strict mode - mysql console:

SELECT @@sql_mode;

I think, we'd need to check if the result contains 'STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER'

@peterkeung
Copy link
Member

Note: upstream, the values were changed to constants: ezsystems#1338

@pkamps pkamps merged commit 3774a54 into master Jan 9, 2018
@pkamps pkamps deleted the search_index_int_val branch July 1, 2018 06:52
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

Successfully merging this pull request may close these issues.

3 participants