Visitar URL original
Ease the debugging of internal pickle errors. by Marco-Sulla · Pull Request #22438 · python/cpython · GitHub
The Wayback Machine - https://web.archive.org/web/20260525140006/https://github.com/python/cpython/pull/22438
Skip to content
/ cpython Public

Ease the debugging of internal pickle errors.#22438

Closed
Marco-Sulla wants to merge 8 commits into
python:masterfrom
Marco-Sulla:pickle
Closed

Ease the debugging of internal pickle errors.#22438
Marco-Sulla wants to merge 8 commits into
python:masterfrom
Marco-Sulla:pickle

Conversation

@Marco-Sulla
Copy link
Copy Markdown

@Marco-Sulla Marco-Sulla commented Sep 28, 2020 •

All pickle error messages was a generic "cannot pickle 'type' object". Added some explaining for every individual error. asserts to individuate in debug mode the error.

Copy link
Copy Markdown
Member

@iritkatriel iritkatriel left a comment

Choose a reason for hiding this comment

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

I think a change like this should come with changes to tests.

Comment thread Objects/typeobject.c Outdated
PyErr_Format(PyExc_TypeError,
"cannot pickle '%.200s' object",
"cannot pickle '%.200s' object: expected " \
"fixed-length instance (tp_itemsize != 0)",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

An alternative message here could be "missing getstate on variable-length object".

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done, thank you.

@Marco-Sulla
Copy link
Copy Markdown
Author

I think a change like this should come with changes to tests.

@iritkatriel Do you mean I should change everything that comes from grep -R "cannot pickle" .?

@iritkatriel
Copy link
Copy Markdown
Member

I think a change like this should come with changes to tests.

@iritkatriel Do you mean I should change everything that comes from grep -R "cannot pickle" .?

It's important to make sure that the lines you are changing are even covered by tests. If not, then you should add whatever tests are missing. If they exist, then you can change the expected message so that your change is verified, and the PR reviewer can see that there is test coverage and that the message fits the test case.

You also need to create a ticket on bugs.python.org and link it to this PR.

@Marco-Sulla
Copy link
Copy Markdown
Author

It's important to make sure that the lines you are changing are even covered by tests

Not sure how to reproduce all these exceptions. I probably have to create buggy CPython types. Must I create them in _pickle and test them in test_pickle?

@iritkatriel
Copy link
Copy Markdown
Member

Some exceptions never make it to users (and sometimes they are sanity checks that can't even happen). In both cases they are not worth changing. Just change the ones you know how to produce.

@Marco-Sulla
Copy link
Copy Markdown
Author

Just change the ones you know how to produce.

OK, I have only to remember how I got one of these errors...
In the meanwhile, I changed the messages with asserts, since correctly Serhiy Storchaka in the bug report pointed me out that is not correct to expose those details to the end user.

Sorry for the confusion.

@iritkatriel
Copy link
Copy Markdown
Member

Serhiy made a good point, but I don't quite see how the asserts are going to help. "Internal debugging" sounds like debugging python itself. But the problem you are trying to solve is that a user type is unpicklable and the user is not getting an indication why.

@Marco-Sulla
Copy link
Copy Markdown
Author

But the problem you are trying to solve is that a user type is unpicklable

Well, no, I reproduced this bug trying to add a builltin, CPython type. The error messages was useful to me to identify the problem. I think it was I wrong the size in the PyTypeObject creation.

@Marco-Sulla
Copy link
Copy Markdown
Author

It seems it fails the tests... probably for the asserts themselves.
Maybe I could add fprintfs, but they sounds to me a little tricky.

I think it's better to close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants