OrchardCore icon indicating copy to clipboard operation
OrchardCore copied to clipboard

SqlQuery with 'return documents' has no results in liquid template

Open bashuss opened this issue 6 months ago • 4 comments

Describe the bug

With features 'Lucene' and 'Sql Queries' on, I defined an Sql Query, that executes fine from the admin. It returns DocumentIds and the return documents checkbox is turned on.

But within a liquid template it is not available or executes in a wrong way: Simply an empty array is returned, while executing form admin shows results. With defined lucene queries, the same liquid code executes fine and shows results.

{% assign blogPosts = Queries.AllBlogPostsSql | query %}
{% for item in blogPosts %}
{{ item | shape_build_display: "Summary" | shape_render }}
{% endfor %}

The sql query executes returns results, when the return documents checkbox is off and GraphQL is configured accordingly.

So it seems like the return documents feature is broken for sql queries.

Also: when deactivating the 'Lucene' feature, the admin 'Queries/All Queries' and the liquid code above throw an error, if there are still undeleted Lucene Queries in the tenant. When these Lucene queries are deleted, all works fine with sql queries.

Orchard Core version

2.0.0-preview-18262

To Reproduce

Steps to reproduce the behavior:

  1. Activate features 'Lucene' and 'Sql Queries' and 'Templates' and use Tenant with BlogTheme.
  2. Create version of 'RecentBlogPosts' Query as Sql Query and as Lucene Query (if not already there). Call add the postfix 'Sql' to the name of the Sql Query, to have different names for the call from liquid. Activate return documents checkbox.

GraphQL for both queries:

{
    "type": "ContentItem/BlogPost"
}

Sql Query (taken from documentation):

select DocumentId
    from ContentItemIndex 
    where Published = true and ContentType = 'BlogPost'

Lucene Query (taken from BlogTheme - I think - was part of my project):

{
  "query": {
    "term": { "Content.ContentItem.ContentType": "BlogPost" }
  },
  "sort": {
    "Content.ContentItem.CreatedUtc": {
      "order": "desc",
      "type": "double"
    }
  },
  "size": 3
}
  1. Create some BlogPosts, if not already available
  2. Override the 'Content__Blog' template with Liquid - use the names of the queries you created :
<div>Lucene here:</div>
{% assign blogPosts = Queries.RecentBlogPosts | query %}
{% for item in blogPosts %}
{{ item | shape_build_display: "Summary" | shape_render }}
{% endfor %}

<div>Sql here:</div>
{% assign blogPostsSql = Queries.RecentBlogPostsSql | query %}
{% for item in blogPostsSql %}
{{ item | shape_build_display: "Summary" | shape_render }}
{% endfor %}
  1. Open Blog page in front end.

  2. If you system acts the same as mine, the Lucene version should show results, the Sql version should not. But both should (though they may be different, as the queries do not exactly match each other).

  3. Turn off 'Lucene' feature in Admin.

  4. Got to menu 'Query/All Queries' in Admin => should throw exception.

  5. Even if you remove the Lucene Part from Template in step 4, the Blog page on the front end should throw an exception.

  6. Turn on the 'Lucene' feature in Admin, remove the Lucene Queries, turn off the 'Lucene' feature again.

  7. Retry steps 8. and 9. -> they should work now.

Expected behavior

  • SqlQuery should behave as LuceneQuery when called from liquid template
  • SqlQuery features should not be corrupted from existing LuceneQuery entries, when Lucene Feature is turned off.

Logs and screenshots

bashuss avatar Aug 06 '24 10:08 bashuss