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

Model labels causes errors in field rendering #19

Open
leogzyl opened this issue Jan 14, 2023 · 7 comments
Open

Model labels causes errors in field rendering #19

leogzyl opened this issue Jan 14, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@leogzyl
Copy link

leogzyl commented Jan 14, 2023

Using the basic blog from lektor quickstart, I get strange behavior with some fields.

Take the start page, page.html for example:

{% extends "layout.html" %}
{% block title %}{{ this.title }}{% endblock %}
{% block body %}
  <h2>{{ this.title }}</h2>
  {{ this.body }}
{% endblock %} 

When running lektor serve...

This markdown:

title: Welcome to myblog! {{"In JINJA!"}} 
---
body:
{{"In JINJA!"}}
This is a basic demo website that shows how to use Lektor for a basic
website with some pages and a blog.

Renders like this:
Screenshot from 2023-01-14 17-07-02

If I make a trivial whitespace change to page.html to force the watcher to do a refresh, everything works:
Screenshot from 2023-01-14 17-10-49

Here's the Page model:

[model]
name = Page
label = {{ this.title }}

[fields.title]
label = Title
type = string

[fields.body]
label = Body
type = markdown

Removing label in the model file makes everything work.

@nixjdm nixjdm added the bug Something isn't working label Apr 11, 2023
@nixjdm
Copy link
Member

nixjdm commented Apr 11, 2023

I've reproduced your steps down get the error to show, and that a whitespace change to the template triggers a successful build. Can you elaborate on what you mean by

Removing label in the model file makes everything work.

Which label? Thank you for the report.

I'm actually experiencing something similar I think in another site.

I'm not sure what's causing this atm, or if it's always been present or somehow came about because of a change in behavior of a dependency.

@nixjdm
Copy link
Member

nixjdm commented Apr 11, 2023

It's worth noting that your report is a failure of jinja to render a string type, whereas mine in another project is a failure to render a markdown type, but you have a markdown type succeeding on the first pass.

This feels like something non-deterministic, yet once a page is built, it's kind of stuck that way until we trick the page into being built again.

@nixjdm
Copy link
Member

nixjdm commented Apr 11, 2023

This sort of seems deterministic. For me, it fails on my other site every time I lektor clean --yes; lektor b, but succeeds every time I lektor clean --yes; lektor s. But in the quickstart project I seem to have the opposite behavior, where building first is the successful one, but going straight to server produces the failing render.

@leogzyl
Copy link
Author

leogzyl commented Apr 16, 2023

I've reproduced your steps down get the error to show, and that a whitespace change to the template triggers a successful build. Can you elaborate on what you mean by

Removing label in the model file makes everything work.

Which label? Thank you for the report.

I'm actually experiencing something similar I think in another site.

I'm not sure what's causing this atm, or if it's always been present or somehow came about because of a change in behavior of a dependency.

I mean the "label" line on the Page model file (line 3 in the last code snippet in my original comment).
To be completely honest, I'm not 100% sure that causes the issue... or simply triggers a rebuild somehow.

I also played around with cleaning and rebuilding and managed to get it to work at times, but never got to the bottom of it, hence the vague bug report.

Anyway, glad to contribute, and thanks for looking into it!

@nixjdm
Copy link
Member

nixjdm commented Apr 19, 2023

I have a fix for this. I'll merge it in and publish a fixed version in a day or two.

@transplier
Copy link

I've set a breakpoint in JinjaContentPlugin##render_as_jinja and I see my test field being rendered properly (in my case, the default author field in the default Blog sample site). At the end of on_process_template_context, the context object is correctly populated with a rendered version of all the fields. However, despite this, Lektor goes on to use the original field values, as if the context object were never modified.

Perhaps Lektor itself is using a different copy of this object? I can debug further but I'd like to hear what @nixjdm found, before expending a bunch of effort. Can I help get the patch over the finish line?

@wayward777
Copy link

I have a fix for this. I'll merge it in and publish a fixed version in a day or two.

The related macros issue (#18) is a bit of a show stopper for me. Will this project be getting any more updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants