Repository: getnikola/nikola

Issue:
Drafts are leaked in feeds
Reported by @kayhayen in the mailing list. Proposed patch breaks tests, so checking things out a bit more carefully.



Discussion:
I am not able to reproduce this yet. Here is a session where I create a new site, create a post with a draft tag, one without it, and build. It only puts "bar" (the non-draft post) in the feed.

```
(nikola)ralsina@salma:~/Desktop/proyectos/nikola/master$ nikola init drafttest


[2013-11-25T14:36:57Z] NOTICE: init: Created empty site at drafttest.
(nikola)ralsina@salma:~/Desktop/proyectos/nikola/master$ 
(nikola)ralsina@salma:~/Desktop/proyectos/nikola/master$ 
(nikola)ralsina@salma:~/Desktop/proyectos/nikola/master$ cd drafttest/
(nikola)ralsina@salma:~/Desktop/proyectos/nikola/master/drafttest$ nikola new_post -t foo --tags=draft posts/foo.rst
Creating New Post
-----------------

Title: foo
Scanning posts....done!
[2013-11-25T14:37:38Z] NOTICE: new_post: Your post's text is at: posts/foo.rst
(nikola)ralsina@salma:~/Desktop/proyectos/nikola/master/drafttest$ nikola new_post -t foo  posts/bar.rst
Creating New Post
-----------------

Title: foo
Scanning posts....done!
[2013-11-25T14:37:47Z] NOTICE: new_post: Your post's text is at: posts/bar.rst
(nikola)ralsina@salma:~/Desktop/proyectos/nikola/master/drafttest$ nikola build
Scanning posts....done!
.  render_listings:output/listings/index.html
.  render_posts:cache/posts/bar.html
.  render_posts:cache/posts/foo.html
.  render_tags:output/categories/index.html
.  render_tags:output/assets/js/tag_cloud_data.json
.  render_indexes:output/index.html
.  render_galleries:output/galleries
.  render_galleries:output/galleries/index.html
.  render_galleries:output/galleries/rss.xml
.  copy_assets:output/assets/js/bootstrap.min.js
.  copy_assets:output/assets/js/imagesloaded.pkgd.min.js
.  copy_assets:output/assets/js/bootstrap.js
.  copy_assets:output/assets/fonts/glyphicons-halflings-regular.woff
.  copy_assets:output/assets/fonts/glyphicons-halflings-regular.eot
.  copy_assets:output/assets/fonts/glyphicons-halflings-regular.ttf
.  copy_assets:output/assets/fonts/glyphicons-halflings-regular.svg
.  copy_assets:output/assets/css/theme.css
.  copy_assets:output/assets/css/docs.css
.  copy_assets:output/assets/css/bootstrap-theme.min.css
.  copy_assets:output/assets/css/bootstrap-theme.css
.  copy_assets:output/assets/css/bootstrap.css
.  copy_assets:output/assets/css/bootstrap-glyphicons.css
.  copy_assets:output/assets/css/colorbox.css
.  copy_assets:output/assets/css/rst.css
.  copy_assets:output/assets/css/bootstrap.min.css
.  copy_assets:output/assets/css/images/ie6/borderTopRight.png
.  copy_assets:output/assets/css/images/ie6/borderTopLeft.png
.  copy_assets:output/assets/css/images/ie6/borderBottomLeft.png
.  copy_assets:output/assets/css/images/ie6/borderTopCenter.png
.  copy_assets:output/assets/css/images/ie6/borderMiddleRight.png
.  copy_assets:output/assets/css/images/ie6/borderMiddleLeft.png
.  copy_assets:output/assets/css/images/ie6/borderBottomCenter.png
.  copy_assets:output/assets/css/images/ie6/borderBottomRight.png
.  copy_assets:output/assets/js/jquery-1.10.2.min.js
.  copy_assets:output/assets/js/flowr.plugin.js
.  copy_assets:output/assets/js/jquery.colorbox-min.js
.  copy_assets:output/assets/img/glyphicons-halflings.png
.  copy_assets:output/assets/img/glyphicons-halflings-white.png
.  copy_assets:output/assets/css/bootstrap-responsive.css
.  copy_assets:output/assets/css/bootstrap-responsive.min.css
.  copy_assets:output/assets/css/images/border.png
.  copy_assets:output/assets/css/images/controls.png
.  copy_assets:output/assets/css/images/overlay.png
.  copy_assets:output/assets/css/images/loading.gif
.  copy_assets:output/assets/css/images/loading_background.png
.  copy_assets:output/assets/js/mathjax.js
.  copy_assets:output/assets/css/code.css
.  render_sources:output/posts/bar.rst
.  render_sources:output/posts/foo.rst
.  render_archive:output/2013/index.html
.  render_archive:output/archive.html
.  render_pages:output/posts/bar.html
.  generate_rss:output/rss.xml
.  render_pages:output/posts/foo.html
.  create_bundles:output/assets/css/all.css
.  create_bundles:output/assets/js/all-nocdn.js
.  create_bundles:output/assets/css/all-nocdn.css
.  create_bundles:output/assets/js/all.js
.  sitemap:output/sitemap.xml
(nikola)ralsina@salma:~/Desktop/proyectos/nikola/master/drafttest$ cat output/rss.xml 
<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Demo Site</title><link>http://getnikola.com/</link><description>This is a demo site for Nikola.</description><atom:link href="http://getnikola.com/rss.xml" type="application/rss+xml" rel="self"></atom:link><language>en</language><lastBuildDate>Mon, 25 Nov 2013 11:37:52 GMT</lastBuildDate><generator>nikola</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>foo</title><link>http://getnikola.com/posts/bar.html</link><description>&lt;p&gt;Write your post here.&lt;/p&gt;</description><guid>http://getnikola.com/posts/bar.html</guid><pubDate>Mon, 25 Nov 2013 11:37:47 GMT</pubDate></item></channel></rss>(nikola)ralsina@salma:~/Desktop/proyectos/nikola/master/drafttest$ 
```

I have checked my history, and indeed the diff went away after my change and removing "rss.xml" to force it to regenerate. Could it be that it was a left over, i.e. adding the "draft" tag had not updated "rss.xml" although it should, and removing rss.xml should have been sufficient.

At least, the posts with draft tags appear to enter "self.timeline" but appears to be filtered out later on, so that is probably OK. 

So I was fooled by a missing dependency. I just did this: 

remove draft tag, rss.xml gets rebuild, I have the post as diff in it. As expected.
add back draft tag, rss.xml does not get rebuild. Not as expected.

So the sequence should be:

create post as non-draft
build
post still in rss.xml
mark post as draft
build
post still visible in rss.xml (bug)

My change is indeed ineffective.

That sounds much more likely!

So, I would have to check that adding/removing draft tags adds/removes the post from the feeds.

Just tested this and I can confirm the behavior as described by @kayhayen on version 6.2.1.

I think I have a simple fix for this.  Will send a PR, shortly. 

If I understand the issue correctly, the issue is with the way doit handles file dependencies - if a file was a dependency for a task prior to this run, but is no longer a dependency, the task is not run, again.  Only, the file dependencies in this run are checked for changes. 


Resolving patch:
diff --git a/nikola/plugins/task/rss.py b/nikola/plugins/task/rss.py
--- a/nikola/plugins/task/rss.py
+++ b/nikola/plugins/task/rss.py
@@ -58,6 +58,11 @@ def gen_tasks(self):
             "feed_length": self.site.config['FEED_LENGTH'],
         }
         self.site.scan_posts()
+        # Check for any changes in the state of use_in_feeds for any post.
+        # Issue #934
+        kw['use_in_feeds_status'] = ''.join(
+            ['T' if x.use_in_feeds else 'F' for x in self.site.timeline]
+        )
         yield self.group_task()
         for lang in kw["translations"]:
             output_name = os.path.join(kw['output_folder'],


Test patch: