BUG: 15010: Check if argument is valid when fetching data from query results

This should fix [#15010](http://public.kitware.com/Bug/view.php?id=15010).