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

Copying items not work correctly with list values #1493

Closed
ils78 opened this issue Sep 12, 2015 · 4 comments
Closed

Copying items not work correctly with list values #1493

ils78 opened this issue Sep 12, 2015 · 4 comments
Labels

Comments

@ils78
Copy link

@ils78 ils78 commented Sep 12, 2015

item = Item()
item['some_field'] = []

c_item = Item(item)
c_item['some_field'].append(1)

print item['some_field'], c_item['some_field']
[1] [1]

@Digenis
Copy link
Member

@Digenis Digenis commented Sep 12, 2015

Not a bug.
See https://docs.python.org/2/library/copy.html

What you do is not meant to deepcopy.
This is the constructor to which you pass an Item instance
and since it receives a mapping, it makes a shallow copy.
It's the same thing you'd expect from dict2 = dict(dict1)
See the documentation link above.

@kmike kmike added the docs label Sep 13, 2015
@kmike
Copy link
Member

@kmike kmike commented Sep 13, 2015

Yeah, I agree with @Digenis: we document Items as providing dictionary-like API.
But the example at http://doc.scrapy.org/en/latest/topics/items.html#other-common-tasks can be improved. So I think it is a documentation issue.

@nramirezuy
Copy link
Contributor

@nramirezuy nramirezuy commented Sep 14, 2015

I wonder if we want to provide a deepcopy shortcut.

@kmike
Copy link
Member

@kmike kmike commented Sep 14, 2015

I like an idea of a deepcopy shortcut.

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

Successfully merging a pull request may close this issue.

None yet
4 participants