-
Notifications
You must be signed in to change notification settings - Fork 253
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
[BugFix] packaging.metadata.Metadata.from_raw(validate=True/False)
may return empty result
#851
Conversation
packaging.metadata.Metadata.from_raw(validate=True/False)
may return empty result
Unfortunately you can't remove that call as that's how we trigger the validation code for each attribute. Plus you didn't update any tests which also means we don't know if the problem you're seeing was actually fixed. Did you want to keep trying to fix it in this PR by adding a test or did you want to open an issue with a reproducer to at least track the bug? |
Oh I see so the bug might be at a different place ... I was wondering the purpose of that line. I'll keep digging to find why it fails |
Co-authored-by: Brett Cannon <[email protected]>
@brettcannon actually I just found the bug: packaging/src/packaging/metadata.py Line 516 in 029f415
So it seems on purpose ... Can you explain maybe why it's explicitly deleted ? |
Yes.
I tried adding a comment, but since you can't comment on deleted lines I had to insert it the link above and I hope I got the dedenting correct.
👍 Having a test case will probably help. You can see what tests we have in https://github.com/pypa/packaging/blob/main/tests/test_metadata.py and where |
@brettcannon actually just above I found the place responsible for that deletion. Though I'm confused why it was manually deleted. Any explanation ? |
Because you don't need the raw data anymore because the appropriate value is cached by the descriptor. Did you actually try using the object and found none of the data was there? Or are you just assuming there's a problem simply because |
To me there's two problems:
# {'_raw': {}, # if validation is True
{'_raw': {
'classifiers': ['Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'Topic :: Utilities',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3',
'],
'metadata_version': '2.1',
'name': 'dummy_project',
},
'classifiers': ['Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'Topic :: Utilities',
'License :: OSI Approved :: Apache Software License',
'Operating System :: OS Independent',
'Programming Language :: Python :: 3',],
'metadata_version': '2.1',
'name': 'dummy_project'
} It's quite messy. I decided to access Maybe the better way is to delete |
Or 3. metadata is messy and not everyone cares whether all fields are valid, and so we make it lazy for for the subset of fields you care about. This API was designed over a span of 18 months with a lot of input from users who work with metadata regularly, so this feature set is very much on purpose.
Hence why
You can't do that as you break lazy access and validation of fields. Please run the test suite locally to see what tests you are breaking with your proposed changes. Because there isn't a bug here I'm going to close the PR. If there's an API question, please open an issue. |
I found either a bug or a very unexpected results inside
packaging.metadata.Metadata.from_raw(validate=True/False)
This function behaves totally different if
validate is True
. Which clearly does not make intuitive sense.Here is a demonstration of the bug.
Long story short, if
validate is True
,from_raw()
returns an empty dictionary. Which is incorrect.getattr()
is the part that actually cause this trouble. So removing it should fix the problem, I'm not entirely clear why it was here in the first place though.https://colab.research.google.com/drive/151JEthOIXDKV1gdFLaJ-MFpPBFQbN1Q_#scrollTo=a54IxVQgS9HP