silverstripe-autocomplete icon indicating copy to clipboard operation
silverstripe-autocomplete copied to clipboard

Source fields initializing incorrectly.

Open patricknelson opened this issue 5 years ago • 1 comments

There are ~two~ three core issues:

  • The source fields parameter in constructor should default to empty array, not null.
  • The check on isset($this->sourceFields) in ->getSourceFields() will always return true thus preventing a default from ever being set.
  • Assuming ->getSourceFields() returned a default, the field name is for the current field, not the field you're searching. So, as it's currently written, it could easily result in a database query error.

Impact: The end result is that it's not possible to leave that field blank, even though the way it's written, it implies it is optional. Leaving this blank results in an error deep in the framework ultimately caused by the filter in this module defining a ->filterAny() entry with a key exactly equal to :PartialMatch (due to the $sourceField being null and coercing to an empty string).

Affects: Appears to affect 3.5.2 and 4.x (or dev-master).

patricknelson avatar Nov 13 '19 23:11 patricknelson

Updated above to reflect that there are three issues, not two (third issue being DB query error if you actually did default the source field on the source DataObject to the current field's name (likely on another DataObject).

patricknelson avatar Nov 13 '19 23:11 patricknelson