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 #323 +/- ##
==========================================
+ Coverage 85.56% 85.81% +0.24%
==========================================
Files 9 9
Lines 2418 2460 +42
Branches 510 522 +12
==========================================
+ Hits 2069 2111 +42
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:49
This was referenced Nov 30, 2026
…y tag ref https://linear.app/ghost/issue/DYA-361 `primary_tag` stands for the slug of a post's first tag when that tag is public, so `primary_tag:-blog` should select every post whose primary tag isn't blog, including posts with none. The expansion negated the slug alone and kept its other conditions, so the filter only selected posts that have a public first tag. Ghost's routes.yaml matching reads the key as one value and keeps the posts without one, so on a site whose home page collection filters on `primary_tag:-blog`, an untagged post got a URL in that collection but never appeared on its index. A negation of a key whose expansion adds conditions now expands as the negated group of what it denies, as `-(primary_tag:blog)` already did, for one value, several values and "does not contain", on `primary_tag`, `primary_author` and any such key. Several negations of one key beside another condition, as in `primary_tag:-a+primary_tag:-b+featured:true`, also lost that condition: combining them into one list wrote the list beside the group of conditions instead of in it, and expanding the key then replaced the group. The combined list now takes the place of the first negation in the group, for every key. For a key that only renames another, that changes rows only where a join table condition sat beside the negations: `tag:-news+tag:-tech+posts_tags.sort_order:0` lost that condition and selected the posts with neither tag at all, and now selects the posts whose first tag is neither. A negation that also says the key has a value, such as `primary_tag:-null`, expands as before.
rob-ghost
force-pushed
the
fix/dya-361-negated-primary-tag
branch
from
November 30, 2026 12:23
f284356 to
bb4ae71
Compare
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
primary_tagstands for the slug of a post's first tag, when that tag is public. Ghost's posts expand it totags.slug:x+posts_tags.sort_order:0+tags.visibility:public, andprimary_authorexpands the same way. A negation expanded in place negated the slug alone and kept the other conditions, soprimary_tag:-blogmeant "has a public primary tag that isn't blog". It left out every post with no primary tag, and every post whose first tag is internal.Ghost's
routes.yamlmatching readsprimary_tagas one value and keeps those posts. On a site whose home page collection filters onprimary_tag:-blog(forum answers recommend it), an untagged post gets a URL in that collection but never appears on its index or pages (Ghost#11728).Several negations beside another condition were worse.
primary_tag:-a+primary_tag:-b+featured:truedroppedfeatured:true.combineNeFilterswrote the combined$ninbeside the$andgroup instead of in it, and expanding the key then replaced that group.Solution
Negations of an expanded key with conditions. They are expanded as the negated group of what they deny, so
primary_tag:-blogselects what the existing workaround-(primary_tag:blog)selects:This covers one value (
-v), several (-[a,b], and-a+-bonce combined) and "does not contain" (-~), on every expansion that adds conditions. A key that only renames another (tag,author) expands in place as before. So does a negation that names null, such asprimary_tag:-null+primary_tag:-x: it also says the key has a value, and it already selects the right posts.Where the combined
$ningoes. It now takes the place of the first negation inside the$and, for every key, rather than only being skipped for expanded keys. The fault was where it was written, which loses a condition whenever anything later rewrites the group. Moving it is as small as skipping expanded keys, and keeps the combined subquery. For an expanded key, the negated group already keeps the condition beside one denied value or list. The move is what keeps it when the list names null, as inprimary_tag:-null+primary_tag:-tech+featured:false. For a key that only renames another, the move changes rows only where a join table condition sits beside the negations. Main dropped that condition, and it now applies.What changes, for which filters
primary_tag:-blog,primary_tag:-[a,b],primary_tag:-~'x'routes.yaml, themes, Content API. Forum answers and small public sites usefilter: primary_tag:-blogfor the home collection. Index pages list more posts: the ones that already had URLs thereprimary_tag:-a+primary_tag:-bwith another condition beside it, alsoprimary_authorroutes.yamlusesprimary_tag:-a+primary_tag:-b+primary_tag:-cprimary_author:-x,primary_author:-[a,b]primary_tag:-null+primary_tag:-tech+featured:falsefeatured:falsedropped: posts 1 and 6 in the tests-(primary_tag:-news)primary_tag:-news+tag:newstag:-a+tag:-bwith a join table condition beside them:tag:-news+tag:-tech+posts_tags.sort_order:0k:-a+k:-bwith any other condition beside them, any other keytoJSON()and the SQL nest the combined list inside the groupprimary_tag:-nullalone,primary_tag:null, positiveprimary_tag:xIn memory
The new tests match the same filters against posts shaped as Ghost's URL service sees them: the primary tag is the first tag if public, and the primary author is the first author. They use Ghost's
routes.yamlexpansions, which mapprimary_tagtoprimary_tag.slug, and select the same posts as the database for every filter tested. Three places can't be compared:primary_tag:-nullalone. The database still selects no post, because null on a many-to-many relation is read the other way round. Not changed here.primary_authorand visibility. In memory it is the first author whatever that author's visibility, and in the database a public one.Left as it is
primary_tag:-nullalone andprimary_tag:nullstill select no post in the database. Null on a many-to-many relation is read the other way round, and fixing that was dropped. In memory they select the posts with a primary tag and without one.keyWithConditionStepand the activity feed's transformers inevent-repository.jscallmongo-utils'expandFiltersdirectly, not nql's. That is harmless today:opened_emails.post_id, and its condition (email_recipients.opened_at:>=0) is on the join table of the same relation. Its negation already compiles to oneNOT INwith that condition inside, which is the complement.data.post_id(withattribution_type:post) is never written negated by Ghost or Admin.Ghost
primary_tagorprimary_author, and no Ghost test pins these queries.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 tags and authors, using Ghost's real post relations and expansions. They check rows from the database and in memory for every filter above, including under an enforced
status:publishedas the Content API applies one. Unit tests cover the expanded JSON and the combined$nin's place. The negation tests fail before this change, and putting the combined$ninback beside the group failsprimary_tag:-null+primary_tag:-tech+featured:false.