Repository navigation
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #321 +/- ##
==========================================
+ Coverage 85.56% 85.67% +0.10%
==========================================
Files 9 9
Lines 2418 2436 +18
Branches 510 519 +9
==========================================
+ Hits 2069 2087 +18
Misses 343 343
Partials 6 6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
rob-ghost
marked this pull request as ready for review
November 30, 2026 11:45
ref https://linear.app/ghost/issue/DYA-361 A row with no value in a column isn't any value, so a filter that says the column is not something should select it. It didn't: SQL's `!=`, `NOT IN` and `NOT LIKE` are unknown for NULL, so "is not", "is none of", "does not contain", "does not start with" and "does not end with" on a column all left out the rows where the column is empty. In Ghost, the members screen's "Name is not" and "Name does not contain" dropped every member without a name from the list, the export, saved views and bulk actions. A negation of values on a column now also selects the rows where it is NULL, so `name:-'Jo'` is `(name IS NULL OR name != 'Jo')`, the same rows `-(name:'Jo')` already selected and the same rows matching a JSON object in memory selects. A negation that names null, such as `name:-null` or `name:-[null,'Jo']`, says the column has a value, so it compiles as before. Negations on a relation key already select the complement through `NOT IN` and are unchanged, and so are the conditions inside a relation's subquery and inside an $elemMatch, which apply to each related row, so Ghost's custom field filters select the same members as before.
rob-ghost
force-pushed
the
fix/dya-361-not-keeps-empty-values
branch
from
November 30, 2026 12:20
4db4676 to
51f0390
Compare
This was referenced Nov 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ref https://linear.app/ghost/issue/DYA-361
Problem
A row with no value in a column isn't any value, so "is not X" should select it. SQL's
!=,NOT INandNOT LIKEare unknown for NULL, so "is not", "is none of", "does not contain", "does not start with" and "does not end with" on a column left out every row where the column is empty. In Ghost, the members screen's "Name is not" and "Name does not contain" drop every member without a name from the list, the export, saved views and bulk actions.Solution
A negation of values on a column also selects the rows where the column is NULL:
These now select the same rows as
-(name:'Jo'), and the same rows nql'squeryJSONmatches in memory.Unchanged, on purpose:
name:-nullstaysIS NOT NULL, andname:-[null,'Jo']compiles exactly as before. It says the column has a value, so it isn't widened to rows without one. It is still wrong: itsNOT IN (NULL, 'Jo')selects nothing, where it should select the members with a name other than Jo. That fix was dropped.$notwith a value that isn't a pattern: only a direct caller can write it, not NQL text, and it still throws, as before.labels.slug:-vipalready selects the complement throughNOT IN (subquery).tags.description:-~'x': they apply to each related row in an existence check, so addingIS NULLthere would not make the filter the complement of its positive form. Left as they are.$elemMatch: read literally on one related row. Ghost's custom field filters use these and have their own "is set" and "is not set". The new tests prove they select the same rows before and after.What changes, for which filters
name:-'Jo',name:-~'jo'("Name is not", "does not contain")html:-~'x'("Text does not contain"),member_id:-<id>("Author is not")k:-v,k:-[a,b],k:-~v,-~^,-~$on any column that can be NULL, any model (postscustom_excerpt,feature_image, tagsdescription…)routes.yaml). No public example of the shape foundstatus:-free,id:-{{id}},email:-'x')col IS NULL ORstatus:-free), themes-(name:-'Jo')segment:-<slug>where the segment is "Name is not Jo"segment:-xto a negated group of the segment's filter. Behind the privatememberSegmentsflagk:-null,k:-[null,a], negations on relation keys, conditions inside a subquery or an$elemMatchThe compiler doesn't know which columns can be NULL, so the SQL text changes for every negated column. For a column declared NOT NULL, MySQL optimises
col IS NULLaway ("IS NULL Optimization" in its manual), sostatus:-freein an email send plans as before. A negation can't narrow an index search by itself, and SQLite plans(name IS NULL OR name != ?)andstatus = ? AND (name IS NULL OR name != ?)the same as the old forms (covering-index scan, and an index search onstatus).Ghost
mongo-knexdependency.mongo-knex. So nql must be released with the new range, or Ghost runs two copies that disagree.member.jscompares with a literal has no negated column. No email send selects more members: Ghost's own recipient filters negate onlystatus, which is never NULL.Release
Each of the three filter fixes needs a minor version, since rows change for existing filters:
@tryghost/mongo-knex@tryghost/nql-lang@tryghost/nqlShip them in one run, after all three merge, so nql's ranges move to the new
mongo-knexandnql-lang:Leave out
--projectsand the run also takes@tryghost/mongo-utilsto 0.8.0, which has no changes, and moves nql's range to^0.8.0. Ghost pinsmongo-utils0.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,nqlandnql-langin one pull request. Its members pipeline callsmongo-knexdirectly, while posts and comments compile through nql's ownmongo-knex. Bumping one without the other runs two copies that disagree. That pull request also updates the two SQL strings thatghost/test/unit/server/models/post.test.jspins:posts.id != ?becomes(posts.id is null or posts.id != ?).Testing
New integration tests on posts with a column that can be NULL, a many-to-many and a one-to-one relation, and a custom-field-shaped relation filtered with
$elemMatch. The column cases fail before this change; the relation, null and$elemMatchcases pass before and after. A negation ANDed after another condition is tested too, so attaching or bracketing the new group wrongly changes rows. Unit tests pin that a list naming null and a$notwithout a pattern compile as before, and SQL strings pinned in mongo-knex's and nql's unit tests are updated.