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

cannot use base.html and subdir/base.html in inheritance chain #89

Closed
krsanky opened this issue Dec 30, 2023 · 16 comments
Closed

cannot use base.html and subdir/base.html in inheritance chain #89

krsanky opened this issue Dec 30, 2023 · 16 comments
Labels

Comments

@krsanky
Copy link

krsanky commented Dec 30, 2023

Hi!,
Djula is great!

I am a django template user from way back.

I have just debugged a weird case with a common inheritance pattern.

I have the bottom "base.html".

In a subdirectory I want to extend it with common features to some module.

So I have "search/base.html" extends "base.html".
And then everything in search/ will extend the local search/base.html.
Pretty typical pattern, i almost make it more confusing explaining it.

Ok with that above pattern I get:
fatal error encountered in SBCL pid 55444 pthread 0x1ac6c06fc30:
Control stack exhausted while pseudo-atomic, fault: 0x1ac40d17fa0, PC: 0x1ac6c066f86

Welcome to LDB, a low-level debugger for the Lisp runtime environment.
ldb>

If I change search/base.html to search/base_search.html (or whatever) it works.

So something with the common base name is causing some loop ? obviously i have no idea :)

Anyways the workaround works but i did narrow it down enough to repro in case this interests you.

Thanks!!!!
Paul SomeoneElse

@krsanky
Copy link
Author

krsanky commented Dec 30, 2023

Further testing... I was messing around with stuff and i have this working:

  • base.html
  • search/base_search.html

not working:

  • base.html
  • search/base.html

ALSO not working:

  • base.html
  • search/base_search.html
  • search/base.html <-- this file isn't referenced or used, just existence messes it up

I had a similar thing happening when implementing a website using builtin golang templates. I was caching the templates in a hashmap by the filename, and it was only considering the base name , not the directory, so a later template with the same name but in a sub-dir would overwrite the template cache of a template with the same name not in a sub-dir (or in a diff sub-dir etc.)

@mmontone
Copy link
Owner

mmontone commented Jan 2, 2024

Thanks for reporting. I'll take a look.

@mmontone
Copy link
Owner

mmontone commented Jan 2, 2024

Yes. Problem is current store doesn't look at file system directories as part of template names, behaves kind of a global database of template filenames, regardless of subdirectories. And so extends "base.html" in search directory tries to extend itself and enters an infinite loop. I don't have a quick fix for that for now. I'd need to rethink how the store manages filenames + directories.

@mmontone mmontone added the bug label Jan 2, 2024
mmontone added a commit that referenced this issue Jan 2, 2024
Give priority to template store search paths over current path

See Github issue #89
@mmontone
Copy link
Owner

mmontone commented Jan 2, 2024

I've pushed a change you can try. It is not a fix, only changes the priority when looking for templates in file system. But could help with this.

@mmontone
Copy link
Owner

mmontone commented Jan 2, 2024

I'm going to try to implement relative includes now. I think they could be a simple to implement solution to this.

mmontone added a commit that referenced this issue Jan 2, 2024
Makes it possible to use relative pathnames in extends.

For example: {% extends "../base.html" %}

See Github issue #89
@mmontone
Copy link
Owner

mmontone commented Jan 2, 2024

I've implemented relative extends, so you can point directly to your templates using "../base.html" in extendsin subdirectories. Does it help?

@krsanky
Copy link
Author

krsanky commented Jan 2, 2024

Thanks for looking at this!
I've started work today after being on vacation so I'm super busy :)
I'll be looking into this in the next day or so.

@krsanky
Copy link
Author

krsanky commented Jan 2, 2024

I found when I implement a template cache that it is easier to just include the full path as the key instead of just the base name. I think this also logically makes sense because base.html is completely a different thing than subdir/base.html. And that's the Django idiom.

But I haven't looked at what you've done so, take that with a grain of salt until I do.

Thanks again!

@mmontone
Copy link
Owner

mmontone commented Jan 2, 2024 via email

@krsanky
Copy link
Author

krsanky commented Jan 3, 2024

; compiling file "/disk1/home/wise/quicklisp/local-projects/djula/src/template-store.lisp" (written 02 JAN 2024 03:40:0
7 PM):
;
; caught ERROR:
; READ error during COMPILE-FILE:
;
; Package PATH does not exist.
;
; Line: 37, Column: 41, File-Position: 1289
;
; Stream: #<SB-INT:FORM-TRACKING-STREAM for "file /disk1/home/wise/quicklisp/local-projects/djula/src/template-st
ore.lisp" {1003A25873}>

; compilation aborted after 0:00:00.001

@krsanky
Copy link
Author

krsanky commented Jan 3, 2024

I got that putting a checkout of the latest djula repo into my ~/quicklisp/local-projects/ directory.
Caveat, this is only the second time I've tried this quicklisp/common-lisp feature so I could be doing it wrong.

mmontone added a commit that referenced this issue Jan 3, 2024
See Github issue #89
@mmontone
Copy link
Owner

mmontone commented Jan 3, 2024

There was a problem with dependencies. Can you try again? Apologies.

@krsanky
Copy link
Author

krsanky commented Jan 7, 2024

Thanks!,

This is worse.

For this example my sub-app is "todo":

Previous this works:
base.html
todo/base_todo.html <-- this extends base.html with {% extends "todo/base_todo.html" %}

Now that doesn't work:

debugger invoked on a SIMPLE-ERROR in thread
#<THREAD "main thread" RUNNING {10013A00A3}>:
No current path for relative pathname: "todo/index.html"

Type HELP for debugger help, or (SB-EXT:EXIT) to exit from SBCL.

restarts (invokable by number or by possibly-abbreviated name):
0: [ABORT] Exit debugger, returning to top level.

((:METHOD DJULA:FIND-TEMPLATE (DJULA:FILESYSTEM-TEMPLATE-STORE T)) #<DJULA:FILESYSTEM-TEMPLATE-STORE {1005D195A3}> "todo/index.html" T) [fast-method]
source: (ERROR "No current path for relative pathname: ~s" NAME)
0]

Did you make sub-directory paths not work at all?

I think it's more idiomatic to django (and jinja) to be able to organize with directories even if you can't reuse the base.html filename.

@mmontone
Copy link
Owner

mmontone commented Jan 7, 2024 via email

mmontone added a commit that referenced this issue Jan 7, 2024
@mmontone
Copy link
Owner

mmontone commented Jan 7, 2024

Thanks!,

This is worse.

For this example my sub-app is "todo":

Previous this works: base.html todo/base_todo.html <-- this extends base.html with {% extends "todo/base_todo.html" %}

Now that doesn't work

This should work again. But I need to take time to test it.

@mmontone
Copy link
Owner

mmontone commented Jan 8, 2024

I've added some tests. Seems to be in good shape to me now.

@mmontone mmontone closed this as completed Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants