Clicking "<number> observations" in species view removes observation field filter

Platform: web

Browser, if a website issue: Firefox 152.0.6

URLs (aka web addresses) of any relevant observations or pages: https://www.inaturalist.org/observations?verifiable=any&view=species&field:Associated%20observation=

Screenshots of what you are seeing:

Description of problem:

Step 1: Filter the explore page for observations with any observation field, e.g. the “Associated observation” one

Step 2: Click the link which says “ observations”, e.g. where it says 2,116 observations under Western Honey Bee

Step 3: Rather than seeing those 2,116 observations as I would expect, my observation field url filter is removed and I am presented with all ~700k Western Honey Bee observations.

I’m a software developer, and I have a copy of iNat site running on my computer. I was able to reproduce the bug in my local copy of iNat.

This bug is caused by this line of code in observation_search.js

    params = _.omitBy( params, function ( value ) {
      return _.isEmpty( value ) && !_.isBoolean( value ) && !_.isNumber( value );
    } );

The OP used field:Associated%20observation=

Because Associated%20observation does not have a value , the line of code above deletes the observation field from params. In order to fix the bug, the code needs to allow for observations fields with no value, e.g. empty string “”.

interesting!

I got to this URL by clicking the “Observations with this field” button you get when clicking on an observation field

Now what’s interesting is when doing so the URL does not contain said “=” initially

image

But clicking the “Species” tab leads to that “=” being inserted:

image

So maybe the real bug is the insertion of that “=”?

Thanks, I can replicate and filed an issue.

Here’s the more of the code.

    var params = _.extend( { }, $location.search( ), options );
    params = _.omitBy( params, function ( value ) {
      return _.isEmpty( value ) && !_.isBoolean( value ) && !_.isNumber( value );
    } );

_.extend treats field:Associated%20observation= differently than it treats field:Associated%20observation.

If there is an ‘=’, _.extend will return Associated%20observation="", which causes _.omitBy to remove Associated%20observation from params.

If there is no “=”, _.extend will return Associated%20observation=true, which causes _.omitBy to include Associated%20observation in the params.

To fix the bug, the dev needs to take into account how _.extend treats =

@tiwane you might want to include the additional details I provided in the bug report.