-
Notifications
You must be signed in to change notification settings - Fork 10.7k
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
Fix FeedExporter not to export empty file #5847
Conversation
+ Fix FeedExporter not to export empty file + Change default value of FEED_STORE_EMPTY
I forgot to mention this as well. Another issue with this patch is whether changing the default values is acceptable. |
Codecov Report
@@ Coverage Diff @@
## master #5847 +/- ##
==========================================
+ Coverage 88.81% 88.88% +0.06%
==========================================
Files 162 162
Lines 11186 11253 +67
Branches 1819 1827 +8
==========================================
+ Hits 9935 10002 +67
Misses 965 965
Partials 286 286
|
I forgot to state this explicitly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea how to test for changes in defaults, even though I think the magnitude of the effect is clearly significant and needs to be tested.
I don’t think we need a specific test for defaults, I think your test changes already cover the default value change as far as we need.
This test needs to be fixed (or deleted) because I made a fix that twisted its original meaning to pass the test.
I agree, and I think changing expectations is the way to go:
--- a/tests/test_feedexport.py
+++ b/tests/test_feedexport.py
@@ -1057,13 +1057,13 @@ class FeedExportTest(FeedExportTestBase):
self._random_temp_filename(): {"format": "csv"},
},
"FEED_STORAGES": {"file": LogOnStoreFileStorage},
+ "FEED_STORE_EMPTY": False,
}
with LogCapture() as log:
yield self.exported_no_data(settings)
- print(log)
- self.assertEqual(str(log).count("Storage.store is called"), 3)
+ self.assertEqual(str(log).count("Storage.store is called"), 0)
@defer.inlineCallbacks
def test_export_multiple_item_classes(self):
Co-authored-by: Adrián Chaves <adrian@chaves.io>
Error. What happened. |
Findings. scrapy/tests/test_feedexport.py Lines 2500 to 2508 in 6ab49e9
This will overwrite the same file when the file write is fast enough and the batch_time matches. |
But if so, isn't this error not limited to this test? Theoretically, if only %(batch_time)s are used, it could occur in practical use as well? |
I can rewrite the whole test to %(batch_id)d if you need to fix it at least, and I'm sure it's the type of error that disappears when you re-run the runner in the first place, though. |
I think I have seen that test fail before, I would not worry about it here, fixing it is out of the scope of this change. |
No merge or additional review yet, any problems? |
@@ -277,18 +277,21 @@ def _store_in_thread(self, file): | |||
class FeedSlot: | |||
def __init__( | |||
self, | |||
file, | |||
exporter, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This now changes a public class, as we made FeedSlot public recently. @kmike @Gallaecio thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only backward-compatible option I can think of at the moment is to keep the current class unchanged, deprecate it, and create a new class with the new API with a new class name (BatchSlot
?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We decided that as this only changes the __init__
signature and the current usage of this class is to receive it in the feed_slot_closed
signal handler, it's fine to just change this.
Thanks @namelessGonbai, @wRAR and @Gallaecio! |
Fixes #872, fixes #5633
There are several problems with this patch.
The explanation for the FeedExporter fix is within the scope of what is already done in the existing tests, so we believe that the fixes to the existing tests are sufficient for testing.
However, I have no idea how to test for changes in defaults, even though I think the magnitude of the effect is clearly significant and needs to be tested.
test_export_no_items_multiple_feeds()
This test from #4621.
This test seems to be testing whether a file descriptor leak has been resolved when
FEED_STORE_EMPTY=False
.FEED_STORE_EMPTY=False
will no longer open the file if the item is missing and this test is no longer meaningful.This test needs to be fixed (or deleted) because I made a fix that twisted its original meaning to pass the test.