Skip to content

🐛 Fixed decimal numbers in filters being read as whole numbers - #322

Open
rob-ghost wants to merge 1 commit into
mainfrom
fix/dya-361-decimal-numbers
Open

rob-ghost wants to merge 1 commit into
mainfrom
fix/dya-361-decimal-numbers

Conversation

@rob-ghost

@rob-ghost rob-ghost commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

ref https://linear.app/ghost/issue/DYA-361

Problem

nql-lang read an unquoted number with parseInt, which drops everything after the decimal point. email_open_rate:<33.5 compared with 33, so it left out members whose open rate is exactly 33, and email_open_rate:33.5 matched them. Ghost's members screen sends these: its Emails sent, Emails opened and Open rate filters accept a decimal, and a saved view stored the decimal text but compared with the whole number.

Solution

A number is read as written:

parse('email_open_rate:<33.5')  // {email_open_rate: {$lt: 33.5}}, was {$lt: 33}
parse('count:01.5')             // {count: 1.5}, was 1

The lexer is unchanged, so what counts as a number is too. Only the value a decimal reads as changes:

Unquoted Before After
33.5, 33.25, 0.5, 01.5 33, 33, 0, 1 33.5, 33.25, 0.5, 1.5
1.0 1 1
007 7 7
-5 "not 5" "not 5"
1e5 the text '1e5' the text '1e5'
.5 the text '.5' the text '.5'
1. an error an error
A digit string longer than a double holds the nearest double the nearest double

dist/parser.js is regenerated with the package's own build script. The only change in it is the one line that converts the number.

What changes, for which filters

Filter Before After Exposure
Members email_open_rate:<33.5, :33.5, :>33.5, and the same on email_count and email_opened_count compared with the whole number compared with the decimal Admin-built, stored (saved views keep the text and now compare as written), bulk actions
Any number filter with a decimal on a number column the whole number the decimal Hand-written private and public. The docs say filter numbers are integers; no public use found
tag:1.5 and other decimals on a text column on MySQL, compared with 1, so it also matched slugs such as 1-5 (MySQL reads '1-5' as the number 1) compared with 1.5, which no slug reads as, since a slug has no point, so it matches nothing Hand-written private and public
Whole numbers, negatives, exponents, dates, relative dates unchanged

Ghost

Ghost pins nql-lang and nql through its catalog and overrides, so the bump reaches Admin's own parsing as well as Core. Admin then stops rewriting a reloaded 33.5 pill to 33. No Ghost code changes: no server-built filter uses a decimal, and no email recipient filter uses a number.

Release

Each of the three filter fixes needs a minor version, since rows change for existing filters:

Package Version Pull request
@tryghost/mongo-knex 0.14.0 #321
@tryghost/nql-lang 0.9.0 #322
@tryghost/nql 0.15.0 #323

Ship them in one run, after all three merge, so nql's ranges move to the new mongo-knex and nql-lang:

pnpm ship:minor --projects=@tryghost/mongo-knex,@tryghost/nql-lang,@tryghost/nql

Leave out --projects and the run also takes @tryghost/mongo-utils to 0.8.0, which has no changes, and moves nql's range to ^0.8.0. Ghost pins mongo-utils 0.7.0 exactly, so it would then load two copies.

A dry run of the command above (pnpm exec nx release version minor --projects=… --dry-run) bumps exactly the three packages and moves both of nql's ranges.

Ghost then bumps mongo-knex, nql and nql-lang in one pull request. Its members pipeline calls mongo-knex directly, while posts and comments compile through nql's own mongo-knex. Bumping one without the other runs two copies that disagree. That pull request also updates the two SQL strings that ghost/test/unit/server/models/post.test.js pins: posts.id != ? becomes (posts.id is null or posts.id != ?).

Testing

Parser tests for decimals (one and two places), leading and trailing zeros, long digit strings, exponents and a trailing point. Rows on nql's members fixture, which gains an open rate column: email_open_rate:<33.5 now selects the member at 33. The decimal tests fail before this change.

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 77e447ba-3f86-46c1-b1ad-4fdca69a38bf
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@codecov-commenter

codecov-commenter commented Nov 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.56%. Comparing base (e0689bd) to head (7627865).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #322   +/-   ##
=======================================
  Coverage   85.56%   85.56%           
=======================================
  Files           9        9           
  Lines        2418     2418           
  Branches      510      510           
=======================================
  Hits         2069     2069           
  Misses        343      343           
  Partials        6        6           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

ref https://linear.app/ghost/issue/DYA-361

The parser read an unquoted number with parseInt, which drops everything after the decimal point, so `email_open_rate:<33.5` compared with 33 and left out the members whose open rate is exactly 33, and `email_open_rate:33.5` matched them. Ghost's members screen sends these: its email number filters accept a decimal, and a saved view kept the decimal text but compared with the whole number. A number is now read as written, so 33.5 is 33.5, 0.5 is 0.5 and 01.5 is 1.5. Whole numbers read as before, including 1.0 as 1 and 007 as 7, and what counts as a number doesn't change: a negative is still a negation, an exponent such as 1e5 is still text, a number ending in a point is still an error, and a number with more digits than a double holds is rounded as before.
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.

2 participants