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

Selective ERROR [nuxt] [request error] [unhandled] [500] Invalid query error. #3088

Closed
danielju91 opened this issue Feb 4, 2025 · 4 comments · Fixed by #3100
Closed

Selective ERROR [nuxt] [request error] [unhandled] [500] Invalid query error. #3088

danielju91 opened this issue Feb 4, 2025 · 4 comments · Fixed by #3100

Comments

@danielju91
Copy link

Environment

WSL Ubuntu 24.04
Node version v23.6.1
[email protected]
[email protected]
@nuxt/[email protected]

Version

3.15.4

Reproduction

https://stackblitz.com/edit/github-kvpjf65n?file=app%2Fcomponents%2Fcontent%2Fblog-posts.vue

The routes where the problem component is displayed:

/
/blog

Description

This behavior happens when I am using queryCollection composable to query markdown content list with ordering.

  • The component was functioning correctly until I added it to one more .md file, app/content/index.md. Originally I only had it in app/content/blog/index.md
  • Upon adding ::blog-posts to the app/content/index.md file, the component started exhibiting the following behavior:
    • When I navigate to the pages through <NuxtLink> buttons (by clicking My name, Main or Blog in the top bar), , the component works as expected.
    • However, when I refresh the page while on that route or go directly to that route, the query fails and the terminal prints:
      ERROR [nuxt] [request error] [unhandled] [500] Invalid query
    • When I remove, the .order('publishedAt', 'DESC') line from the query chain inside blog-posts.vue this symptom goes away, the above error no longer occurring upon refreshing or directly visiting the problem routes by typing in the url. The list of posts display as intended as well.

(When I remove the highlighted line, the query succeeds again, regardless of method used to load the pages)
Image

Additional context

No response

Logs

✔ Vite server hmr 20 files in 446.46ms
collectionQuery Promise { <unknown> }

 ERROR  [nuxt] [request error] [unhandled] [500] Invalid query


undefined
Copy link
Member

farnabaz commented Feb 4, 2025

Thanks for providing reproduction @danielju91
Seems that there is an issue with query security validator, which does not allow upper-case letters in order. Could you try by renaming publishedAt to published_at or anything with lowercase characters?
This will be workaround for the issue. I release a patch in next days

@mklueh
Copy link

mklueh commented Feb 4, 2025

I have the same issue with a simple .all() query while trying to migrate to 3.0.1

Image

content sits in /content/game/

And as it did not work without the nuxt.content.ts at all, I've dropped in

import { defineContentConfig, defineCollection } from "@nuxt/content";

export default defineContentConfig({
  collections: {
    game: defineCollection({
      source: "game/*.md",
      type: "page"
    })
  }
});

This is a sample markdown:

---
id: 4suZqQlptKsxR6bm0UHzgHq
title: Some title
slug: ssome-slig
link: https://www......
date: 2025-01-05T19:07:00.000Z
description: Some
  multi
  line
  description
cover: /images/uploads/6sxf1tlkudiz6l.jpg
facts:
  - name: Fact 1
    value: "62"
  - name: Category
    value: Some Category
  - name: Rating
    value: 4.5/5
images:
  - image: /images/uploads/a.jpg
  - image: /images/uploads/b.jpg
  - image: /images/uploads/c.jpg
---

(also tried content/game/*.md) just in case

Nothing works and I only get the query error out of it.

The migration docs read as if the transition would be seamless except having to adjust the query syntax, but it seems there is something else

@danielju91
Copy link
Author

danielju91 commented Feb 5, 2025

@farnabaz Thank you for the workaround solution. I confirm that changing publishedAt to published_at does get rid of the bug.

I should add that this means having to change the publishedAt in the schema (inside content.config.ts) and inside the .select method in addition to inside the .order method. Only changing the publishedAt inside the .order to published_at will return error:
ERROR [nuxt] [request error] [unhandled] [500] no such column: "published_at" - should this be a string literal in single-quotes?

@farnabaz
Copy link
Member

farnabaz commented Feb 6, 2025

@mklueh I'm not sure why you facing this error. Could you provide a reproduction?

I just checked with your explanation in Stackblitz and seems fine, Check out https://stackblitz.com/edit/github-mxtmkhbd?file=content.config.ts,content%2Fgame%2Ffirst.md,app%2Fpages%2Findex.vue

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 a pull request may close this issue.

3 participants