Skip to content

Fix JsonItemExporter puts lone comma in the output if encoder fails #5952

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

Merged

Conversation

adnan-awan
Copy link
Contributor

@adnan-awan adnan-awan commented Jun 15, 2023

Continuation of #3111.

Resolves #3090, closes #3111.

Cathal Garvey and others added 6 commits February 7, 2018 12:43
@wRAR
Copy link
Member

wRAR commented Jun 15, 2023

Can you please check why some existing tests failed? Looks like some extra commas are added.

@codecov
Copy link

codecov bot commented Jul 10, 2023

Codecov Report

Merging #5952 (5fc0612) into master (d2e7f6e) will increase coverage by 0.34%.
The diff coverage is 95.10%.

❗ Current head 5fc0612 differs from pull request most recent head fff055b. Consider uploading reports for the commit fff055b to get more accurate results

@@            Coverage Diff             @@
##           master    #5952      +/-   ##
==========================================
+ Coverage   88.86%   89.21%   +0.34%     
==========================================
  Files         162      162              
  Lines       11199    11289      +90     
  Branches     1821     1833      +12     
==========================================
+ Hits         9952    10071     +119     
+ Misses        962      927      -35     
- Partials      285      291       +6     
Impacted Files Coverage Δ
scrapy/__init__.py 84.21% <0.00%> (ø)
scrapy/downloadermiddlewares/httpcache.py 93.97% <ø> (ø)
scrapy/cmdline.py 67.96% <50.00%> (ø)
scrapy/utils/engine.py 77.27% <71.42%> (-6.94%) ⬇️
scrapy/utils/request.py 96.09% <77.77%> (-1.53%) ⬇️
scrapy/utils/display.py 93.10% <85.71%> (+0.24%) ⬆️
scrapy/utils/url.py 96.36% <86.66%> (-3.64%) ⬇️
scrapy/utils/decorators.py 76.66% <88.88%> (+1.66%) ⬆️
scrapy/utils/deprecate.py 93.05% <89.47%> (-2.40%) ⬇️
scrapy/utils/python.py 88.75% <95.83%> (ø)
... and 22 more

... and 2 files with indirect coverage changes

itemdict = dict(self._get_serialized_fields(item))
data = to_bytes(self.encoder.encode(itemdict), self.encoding)
except TypeError as e:
raise e
Copy link
Member

@wRAR wRAR Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this catch+reraise does anything (except breaking the traceback IIRC)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wRAR thanks for your comment.

Actually, this test expect the TypeError. Do you've something better in your mind for its replacement?.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But as this code does nothing then removing it won't break the test.

self.assertRaises(TypeError, self.ie.export_item, i2)
self.ie.export_item(i3)
self.ie.finish_exporting()
print(f"values are=={self.output.getvalue()}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is a debug print?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah, I'll remove it thanks! :)

@kmike kmike merged commit 5d91ea1 into scrapy:master Jul 22, 2023
@kmike
Copy link
Member

kmike commented Jul 22, 2023

Thanks @adnan-awan!

@adnan-awan adnan-awan deleted the jsonitemexporter_puts_lone_comma-issue-3090 branch July 24, 2023 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JsonItemExporter puts lone comma in the output if encoder fails
3 participants