Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inverse tag filtering in dynamic routing works incorrectly #9950

Closed
vladimir-vg opened this issue Oct 5, 2018 · 15 comments
Closed

Inverse tag filtering in dynamic routing works incorrectly #9950

vladimir-vg opened this issue Oct 5, 2018 · 15 comments
Assignees
Labels
bug [triage] something behaving unexpectedly server / core Issues relating to the server or core of Ghost

Comments

@vladimir-vg
Copy link

Issue Summary

Collection route renders page with zero items, when inverse tag filter is specified.

To Reproduce

  1. Create tag with "en" slug.
  2. Attach this tag to some of the stories
  3. Upload a following routes.yaml. Guided by this page: https://help.ghost.org/article/112-multi-language-content
routes:

collections:
  /:
    permalink: /{slug}/
    filter: tag:-en
    template:
      - index
  /en/:
    permalink: /en/{slug}/
    filter: tag:en
    template:
      - index

taxonomies:
  tag: /tag/{slug}/
  author: /author/{slug}/
  1. Restart Ghost (just in case).
  2. Open /en/ -- see stories that were tagged at step 2. All as expected.
  3. Open / -- no items, empty page. Expected to see all stories that are not tagged with "en".

If I rewrite filter: tag:-en as filter: tag:-[en] it has same effect.

Interestingly, if I comment out filter: tag:-en for the / route, then behavior is reversed. Empty list for /en/ (unexpected) and all stories for / (expected).

Technical details:

  • Ghost Version: 2.2.0
  • Node Version: v6.9.4
  • Browser/OS: Ubuntu 14.04 64bit
  • Database: MySQL Ver 14.14 Distrib 5.5.61, for debian-linux-gnu (x86_64) using readline 6.3

No errors in /var/www/ghost/content/logs/http___vladimir_vg_me__production.error.log. Just empty file.

This is the website: http://vladimir-vg.me

@vladimir-vg
Copy link
Author

Noticed following on this page: https://docs.ghost.org/docs/dynamic-routing

Beta requirement: Specify inverse filters!
In the current beta version of Dynamic Routing it's necessary to specify the inverse of filters in earlier collections so that pagination is correct.

Tried to change order of route definitions -- no effect.

@kirrg001 kirrg001 self-assigned this Oct 5, 2018
@kirrg001
Copy link
Contributor

kirrg001 commented Oct 5, 2018

@vladimir-vg Hey :) Will look at your report on Monday!

@vladimir-vg
Copy link
Author

Thanks! If you need more information don't hesitate to ask.

@kirrg001
Copy link
Contributor

kirrg001 commented Oct 6, 2018

I can't reproduce this 🤔

I tagged two posts with en. /en/ shows 2 posts.
/ shows the rest.

@kirrg001 kirrg001 added the needs:info [triage] Blocked on missing information label Oct 6, 2018
@cotko
Copy link
Contributor

cotko commented Oct 7, 2018

@kirrg001 I just wanted to report same thing.
I made 4 new posts, 2 tagged as de language and two without any tags (which would be a default language). Using -de does not pick up the two without any tags, it seems as if query joins tags to the posts and if posts are not tagged at all, then they are also filtered out, although it would make sense that they should be picked up, since they do not contain the de tag.

@kirrg001
Copy link
Contributor

kirrg001 commented Oct 7, 2018

@cotko Could you please share your routes.yaml file? Thanks 👍

@cotko
Copy link
Contributor

cotko commented Oct 7, 2018

@kirrg001 Just tried with the one @vladimir-vg posted above and it's the same. If you go and edit some of the posts and just remove all tags from them, you will see that they disappear from the blog at the default route, where tag:-en is used. Then if you tag those posts again with anything but en they appear again.

@kirrg001
Copy link
Contributor

kirrg001 commented Oct 7, 2018

Thanks. Will play with this. I guess it's caused by having posts with no tags at all 🤔

@kirrg001 kirrg001 added server / core Issues relating to the server or core of Ghost bug [triage] something behaving unexpectedly and removed needs:info [triage] Blocked on missing information labels Oct 7, 2018
@kirrg001
Copy link
Contributor

kirrg001 commented Oct 7, 2018

Okay had some more time to reproduce now. Can confirm, inverse filtering does not work correctly.

I think i even see a couple of bugs with negation.

This filter troubles: filter=tag:-en

  1. The SQL query does not respect posts which have no tags. The SQL query does not return posts with no tags, but it should IMO.

  2. The SQL query has problems when the post is tagged with multiple tags. e.g. "test" has two tags "en" and "beautiful". The first tag is en, but the second is not en. The SQL query must say "if one tag is en, then do not return the result". But the SQL query results in true, because "beautiful" is not en. You won't see these posts when you serve the page, because Ghost will filter them out, because they are owned by a different collection.


Dynamic Routing is currently in beta. We will work on this report as soon as possible 👍 Thanks for your help.

@kirrg001
Copy link
Contributor

kirrg001 commented Oct 7, 2018

Little update:

This mis-behaviour is caused by GQL. GQL generates the wrong queries.

We will fix that in NQL and not in GQL. NQL is the "new" GQL, but it's not finished yet. Ghost does not fully use NQL yet.

I've raised an issue in NQL to keep track of it.

See also this issue.

@kirrg001
Copy link
Contributor

kirrg001 commented Oct 7, 2018

Similar/Same report: #9923

@vladimir-vg
Copy link
Author

Okay, so current workaround: create any tag and attach to all stories.

@kirrg001
Copy link
Contributor

This bug was fixed in Ghost 2.8.0.

@pascalandy
Copy link

I confirm this it is working.

# filters out few tags from Ghost's homepage
routes:
  /:
    controller: channel
    filter: tag:-[business]
# which excludes tag: [business]

collections:
  /:
    permalink: /{slug}/ 
    template:
      - index

taxonomies:
  tag: /tag/{slug}/
  author: /author/{slug}/

@gnimmelf
Copy link

gnimmelf commented Aug 5, 2019

I guess the team is on top of it, but it's still very confusing for a newcomer, even with plenty technical background.

I have the following routes.yaml, and it only works on positive tag filtering, / still includes those tags.

collections:
  /:
    permalink: /{slug}/
    template: index
    filter: 'tag:-[hash-lang-no]'

  /no/:
    permalink: /no/{slug}/
    template: index
    filter: 'tag:hash-lang-no'

However, @pascalandy's fix works, applying a channel for /:

So, is it fixed, ref @kirrg001 mentions v2.8.0 above, but latest is 2.26.0 (am I missing s.th?), or the workaround tagging all posts by vladimir-vg, or pascalandy's by using a channel-controller?

daniellockyer pushed a commit to TryGhost/framework that referenced this issue Jun 15, 2021
refs #10105, closes #10108, closes TryGhost/Ghost#9950, refs TryGhost/Ghost#9923, refs TryGhost/Ghost#9916, refs TryGhost/Ghost#9574, refs TryGhost/Ghost#6345, refs TryGhost/Ghost#6309, refs TryGhost/Ghost#6158, refs TryGhost/GQL#16

- removed GQL dependency
- replaced GQL with our brand new NQL implementation
- fixed all known filter limitations
- GQL suffered from some underlying filter bugs, which NQL tried to fix
- the bugs were mostly in how we query the database for relation filtering
- the underlying problem was caused by a too simple implementation of querying the relations
- mongo-knex has implemented a more robust and complex filtering mechanism for relations
- replaced logic in our bookshelf filter plugin
- we pass the custom, default and override filters from Ghost to NQL, which then are getting parsed and merged into a mongo JSON object. The mongo JSON is getting attached by mongo-knex.

NQL: https://github.com/NexesJS/NQL
mongo-knex: https://github.com/NexesJS/mongo-knex
daniellockyer pushed a commit to TryGhost/framework that referenced this issue Jun 15, 2021
refs #10105, closes #10108, closes TryGhost/Ghost#9950, refs TryGhost/Ghost#9923, refs TryGhost/Ghost#9916, refs TryGhost/Ghost#9574, refs TryGhost/Ghost#6345, refs TryGhost/Ghost#6309, refs TryGhost/Ghost#6158, refs TryGhost/GQL#16

- removed GQL dependency
- replaced GQL with our brand new NQL implementation
- fixed all known filter limitations
- GQL suffered from some underlying filter bugs, which NQL tried to fix
- the bugs were mostly in how we query the database for relation filtering
- the underlying problem was caused by a too simple implementation of querying the relations
- mongo-knex has implemented a more robust and complex filtering mechanism for relations
- replaced logic in our bookshelf filter plugin
- we pass the custom, default and override filters from Ghost to NQL, which then are getting parsed and merged into a mongo JSON object. The mongo JSON is getting attached by mongo-knex.

NQL: https://github.com/NexesJS/NQL
mongo-knex: https://github.com/NexesJS/mongo-knex
daniellockyer pushed a commit to TryGhost/framework that referenced this issue Jun 15, 2021
refs #10105, closes #10108, closes TryGhost/Ghost#9950, refs TryGhost/Ghost#9923, refs TryGhost/Ghost#9916, refs TryGhost/Ghost#9574, refs TryGhost/Ghost#6345, refs TryGhost/Ghost#6309, refs TryGhost/Ghost#6158, refs TryGhost/GQL#16

- removed GQL dependency
- replaced GQL with our brand new NQL implementation
- fixed all known filter limitations
- GQL suffered from some underlying filter bugs, which NQL tried to fix
- the bugs were mostly in how we query the database for relation filtering
- the underlying problem was caused by a too simple implementation of querying the relations
- mongo-knex has implemented a more robust and complex filtering mechanism for relations
- replaced logic in our bookshelf filter plugin
- we pass the custom, default and override filters from Ghost to NQL, which then are getting parsed and merged into a mongo JSON object. The mongo JSON is getting attached by mongo-knex.

NQL: https://github.com/NexesJS/NQL
mongo-knex: https://github.com/NexesJS/mongo-knex
daniellockyer pushed a commit to TryGhost/framework that referenced this issue Jun 15, 2021
refs #10105, closes #10108, closes TryGhost/Ghost#9950, refs TryGhost/Ghost#9923, refs TryGhost/Ghost#9916, refs TryGhost/Ghost#9574, refs TryGhost/Ghost#6345, refs TryGhost/Ghost#6309, refs TryGhost/Ghost#6158, refs TryGhost/GQL#16

- removed GQL dependency
- replaced GQL with our brand new NQL implementation
- fixed all known filter limitations
- GQL suffered from some underlying filter bugs, which NQL tried to fix
- the bugs were mostly in how we query the database for relation filtering
- the underlying problem was caused by a too simple implementation of querying the relations
- mongo-knex has implemented a more robust and complex filtering mechanism for relations
- replaced logic in our bookshelf filter plugin
- we pass the custom, default and override filters from Ghost to NQL, which then are getting parsed and merged into a mongo JSON object. The mongo JSON is getting attached by mongo-knex.

NQL: https://github.com/NexesJS/NQL
mongo-knex: https://github.com/NexesJS/mongo-knex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug [triage] something behaving unexpectedly server / core Issues relating to the server or core of Ghost
Projects
None yet
Development

No branches or pull requests

6 participants