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

List of fields incorrectly accessed for dataclass items #4667

Closed
tadejsv opened this issue Jul 8, 2020 · 1 comment · Fixed by #4668
Closed

List of fields incorrectly accessed for dataclass items #4667

tadejsv opened this issue Jul 8, 2020 · 1 comment · Fixed by #4668
Assignees
Labels
Milestone

Comments

@tadejsv
Copy link

tadejsv commented Jul 8, 2020

Description

If I make a dataclass item and want to export to csv, I get this error:

...
  File "/home/tadej/miniconda3/envs/main/lib/python3.7/site-packages/scrapy/exporters.py", line 251, in _write_headers_and_set_fields_to_export
    self.fields_to_export = list(item.fields.keys())
AttributeError: 'CompanyItem' object has no attribute 'fields'

The problem stems from here

https://github.com/scrapy/scrapy/blob/master/scrapy/exporters.py#L243-L253

There should be an additional if case checking if the item is of type dataclass, and then accessing the fields differently, perhaps as

[field.name for field in fields(item)]
@elacuesta elacuesta added the bug label Jul 8, 2020
@elacuesta
Copy link
Member

Indeed, seems like we missed that one in #3881. Thanks for the report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants