Skip to content

bug: return the parent ways and relations for wr(bn) with tag filters - #21

Open
cldellow wants to merge 1 commit into
fossgis:masterfrom
cldellow:recurse-node-wr-ranges
Open

cldellow wants to merge 1 commit into
fossgis:masterfrom
cldellow:recurse-node-wr-ranges

Conversation

@cldellow

@cldellow cldellow commented Nov 30, 2026 •

Copy link
Copy Markdown

Fixes drolbr#810

Overpass queries are a statement that generates the initial set of results plus some number of constraints that further refine them.

wr(bn) is a Recurse_Statement, and returns correct results.

wr(bn)[highway] is a Query_Statement with a Recurse_Constraint and returns incorrect results.

Conveniently, Overpass itself provides two ways to exercise this bug:

  • wr(bn.n)[highway] must be equal to (way(bn.n)[highway]; rel(bn.n)[highway];) (and the way(bn.n)[highway] and rel(bn.n)[highway] forms don't have this bug)
  • wr(bn) must be equal to wr(bn)(if:1) (and the latter form forces the Query_Statement + Recurse_Constraint behaviour)

The constraint mode didn't correctly filter data, so wr(bn.s) with a tag filter fell back to the tag filter over the whole database: it returned nothing or failed with "Filters too weak" at the current date, and returned unrelated relations at a past date.

The fix is to apply the same filters as the statement version does.

On a Nova Scotia extract:

  [out:csv(::count)];
  node(44.6470,-63.5760,44.6490,-63.5730)->.s;
  wr(bn.s)["highway"];
  out count;

returned 0 ways in 0.53 s, and now returns 141 in 0.01 s, the same as (way(bn.s)["highway"]; rel(bn.s)["highway"];).

@cldellow

cldellow commented Nov 30, 2026 •

Copy link
Copy Markdown
Author

The initial PR description had an error when describing wr(bn) as being equal to (way(bn); rel(bn);). This equivalence does not hold, because way(bn) overwrites the default set _ that rel(bn) will then use.

The equivalence of wr(bn.n) and (way(bn.n); rel(bn.n);) does hold -- I introduced this error when simplifying the example shown in the PR, it wasn't present in the fuzz or property-based testing. I've updated the PR's description, and still believe the rest of the reasoning holds.

Thanks to @mmd-osm who very speedily noted this in drolbr#810 (comment).

…ters

In a query statement, wr(bn.s) is a Recurse_Constraint of type
RECURSE_NODE_WR, which none of the constraint's methods handled:
get_way_ranges and get_relation_ranges returned global ranges, get_data
collected nothing, and filter dropped all ways and kept attic relations
unfiltered. So wr(bn.s) with a tag filter fell back to the tag filter
over the whole database: it returned nothing or failed with "Filters too
weak" at the current date, and returned unrelated relations at a past
date.

Handle RECURSE_NODE_WR in these methods as RECURSE_NODE_WAY for ways and
RECURSE_NODE_RELATION for relations, as the standalone wr(bn.s)
statement does.

The regression tests regression_wr_bn_tag_filter and
regression_wr_bn_tag_filter_date cover the current and past-date cases.

On a Nova Scotia extract:

  [out:csv(::count)]; node(44.6470,-63.5760,44.6490,-63.5730)->.s;
  wr(bn.s)["highway"]; out count;

returned 0 ways in 0.53 s, and now returns 141 in 0.01 s, the same as
(way(bn.s)["highway"]; rel(bn.s)["highway"];).

Co-Authored-By: Colin Dellow <cldellow@gmail.com>
@cldellow
cldellow force-pushed the recurse-node-wr-ranges branch from 3ee5733 to 3bfdade Compare December 1, 2026 01:22
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.

wr(bn) with a tag filter returns nothing, "Filters too weak", or unrelated relations

2 participants