lektor / lektor-tags

For each tag on your site, build a list of pages with that tag. This can be used for standard tag-based blog navigation.
MIT License
27 stars 6 forks source link

Strange exceptions #2

Closed asyncee closed 5 years ago

asyncee commented 8 years ago

Hello!

There are some strange behaviour when using your plugin: if i do any mistake (in configuration, or, say in template) then exception Pad went away will be raised.

It took few hours to understand what is really going on to fix this issue in my project — everything because of unrelated stacktrace:

Traceback (most recent call last):
  File "/home/asyncee/.local/lib/lektor/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/asyncee/.local/lib/lektor/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/home/asyncee/.local/lib/lektor/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/asyncee/.local/lib/lektor/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/asyncee/.local/lib/lektor/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/asyncee/.local/lib/lektor/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/asyncee/.local/lib/lektor/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/asyncee/.local/lib/lektor/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/asyncee/.local/lib/lektor/lib/python2.7/site-packages/lektor/admin/modules/serve.py", line 148, in serve_artifact
    return serve_up_artifact(path)
  File "/home/asyncee/.local/lib/lektor/lib/python2.7/site-packages/lektor/admin/modules/serve.py", line 127, in serve_up_artifact
    artifact_name, filename = li.resolve_artifact('/' + path, pad)
  File "/home/asyncee/.local/lib/lektor/lib/python2.7/site-packages/lektor/admin/webui.py", line 60, in resolve_artifact
    prog, _ = builder.build(source)
  File "/home/asyncee/.local/lib/lektor/lib/python2.7/site-packages/lektor/builder.py", line 1070, in build
    prog.build()
  File "/home/asyncee/.local/lib/lektor/lib/python2.7/site-packages/lektor/build_programs.py", line 83, in build
    self.produce_artifacts()
  File "/home/asyncee/.local/lib/lektor/lib/python2.7/site-packages/lektor_tags.py", line 56, in produce_artifacts
    sources=list(self.source.iter_source_filenames()))
  File "/home/asyncee/.local/lib/lektor/lib/python2.7/site-packages/lektor/sourceobj.py", line 41, in iter_source_filenames
    fn = self.source_filename
  File "/home/asyncee/.local/lib/lektor/lib/python2.7/site-packages/lektor/sourceobj.py", line 158, in source_filename
    return self.record.source_filename
  File "/home/asyncee/.local/lib/lektor/lib/python2.7/site-packages/lektor/db.py", line 534, in source_filename
    return os.path.join(self.pad.db.to_fs_path(self['_path']),
  File "/home/asyncee/.local/lib/lektor/lib/python2.7/site-packages/lektor/sourceobj.py", line 67, in pad
    raise AttributeError('The pad went away')
AttributeError: The pad went away

In my case mistakes were related with:

a) tags.html instead of tag.html template b) {{ this.pagination }} is unsupported by plugin

So, the problem is that i spend a few hours to notice that problems are not in lektor core and not in your plugin, but in my code.

asyncee commented 8 years ago

More notes:

a) tag page not working in admin with described exception b) related artifacts do not rebuild automatically, for example, when i add new tags to blog-post (new tag pages not created) c) lektor clean && lektor build gives correct output

If you need to see the code, please check here. Final result you can see here.

eigengrau commented 8 years ago

I’m also seeing this. This is somehow related to SourceObject.pad being a weakref. You can see that this plays into the issue when you apply the following, seemingly nonsensical, patch, which will keep the pad from being garbage collected.

diff --git a/lektor_tags.py b/lektor_tags.py
index d75c8c8..666317a 100644
--- a/lektor_tags.py
+++ b/lektor_tags.py
@@ -23,6 +23,7 @@ def __init__(self, parent, tag):
         VirtualSourceObject.__init__(self, parent)
         self.plugin = parent.pad.env.plugins['tags']
         self.tag = tag
+        self.i_want_to_live = self.pad

     @property
     def items(self):

I don’t grok Lector’s data model or API well enough to say whether this is a bug in Lektor or in lektor-tags, though.

p-lewis commented 8 years ago

@eigengrau, that was helpful. I was seeing the same issue, and the patch to lektor_tags also seems to have resolved it.

keikoro commented 7 years ago

@eigengrau Thanks so much for posting a fix! I don't know why I didn't come across this issue earlier, had been looking for a solution to that "Pad went away" error for a while already!

ericmjl commented 6 years ago

I have also been Googling around. "The pad went away" is a really weird error message to throw. Is there a PR we can put in to fix this, @nixjdm?

nixjdm commented 5 years ago

For a while I was able to reproduce this with https://github.com/ags-slc/lektor-test (once the config was corrected). @eigengrau's solution making another strong reference to the pad did fix it for me. I'll include that fix and make a new release of this plugin, but the issue deserves some thought in lektor core too I think, so I'll also make note of it over there.

ericmjl commented 5 years ago

@nixjdm thank you so much for looping back!

nixjdm commented 5 years ago

@ericmjl You're welcome! Sorry you had to wait so long!