-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Frontmatter data stripped off from collection entry data #12404
Comments
Update Probably this doc info implies the mentioned behavior of stripping off data properties that are not declared in schema:
When there is no collection schema defined, all frontmatter data is included in collection entry data as expected. Wondering though, if a log message regarding the stripped data would be useful, or some explicit mentioning of it in docs; but maybe its just me. |
It seems that a docs PR was raised. I am going to close this issue |
@ematipico I'd like to ask, because I don't have experiences with this and I didn't get a feedback about a behavior I think might be potentially a bug: So it is a designed behavior for collection schema that when I get some data from I'd expect, that I should filter my data during API request time and that I should be warned if some data would be somehow auto-excluded from the returned collection entry data, in this case because of defined collection I do apologize, I don't have an opinion about this, I only try to get a hang of it how it works :) |
I know this issue is closed, and we're discussing in a docs PR but I'm not entirely sure whether this is something to document. And the latest question here makes it sound like a question re: whether it's possible to surface an error:
So quick re-open here just to check: @ascorbic Is there some way for the loader to know/evaluate whether the loaded data in fact does match the schema vs silently only processing what it's been asked for in order to surface an error? It seems in this case, (if I understand correctly), Juraj didn't fully define all properties as an oversight (not looking for some intentional behaviour re: only defining some properties of the data). So I don't think it's really a documentation issue since we do already say clearly "define everything in your schema!" and this doesn't seem to be a request to further explain some fancier use case re: ignoring some of your data. It seems instead explanation of what went wrong in the case of, by mistake, not following what the docs currently say. 😄 It seems like what happened here is not a docs issue, but an expectation of what happens in the case of an error. Is the information known to Astro at the right time in order to provide such an error? I think this might be a better path than a line in docs, in the case that someone's loaded data doesn't match their schema. Just wondering whether that's possible! I think when this becomes something for docs is if we do explicitly want to call attention to a use case like, "Hey, if you only want to import some of the properties to make your collection, just define the ones you want in your schema!" But this certainly won't be the expected case, and I would assume people are free to just ignore those properties in their Astro project if they don't want to use them? This doesn't sound like the happy path to me, but if there are common/legitimate use cases for this and we decide it's helpful to show them, then I think that's when we change docs. Otherwise, I think telling people they have to define every property in their schema is what docs should be doing. |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
Frontmatter properties, that aren't defined via zod schema in content collection
config.ts
, do not appear in returned collection entrydata
object. Probably a feature, but haven't read about it in docs and was surprised a bit by it, so I'm filing a report just in case.config.ts
collection md file entry
astro template
What's the expected result?
If it's a bug
All existing frontmatter data should be included in the collection entry
data
object, ie following the example above:If it's a feature
There should be a terminal log about this intervention.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-fggxst?file=src%2Fcontent%2Fconfig.ts,src%2Fpages%2Findex.astro,src%2Fdata%2Fcoll%2Fone.md
Participation
The text was updated successfully, but these errors were encountered: