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

Fix spans weak ref in doc copy #7225

Merged
merged 3 commits into from Feb 28, 2021
Merged

Conversation

svlandeg
Copy link
Member

Description

Doc.copy() would corrupt the doc reference stored in doc.spans, because the copied spans would keep pointing to the old doc, which would get garbage-collected at some point, eventually leading to dead references.

Proposed solution: allow Spangroups.copy() to optionally define a new Doc object, so that Doc.copy() sets the correct new Doc.

Types of change

bug fix

Checklist

  • I have submitted the spaCy Contributor Agreement.
  • I ran the tests, and all new and existing tests passed.
  • My changes don't require a change to the documentation, or if they do, I've added all required information.

@svlandeg svlandeg added bug Bugs and behaviour differing from documentation feat / doc Feature: Doc, Span and Token objects labels Feb 27, 2021
@svlandeg
Copy link
Member Author

I guess an alternative solution would be to have a doc.spans setter which makes sure that you can't set an incompatible SpanGroups object on a given Doc - because I can imagine this bug popping up in other places as well.

@honnibal
Copy link
Member

Ah good catch, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bugs and behaviour differing from documentation feat / doc Feature: Doc, Span and Token objects
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants