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

ISO date errors in _strptime are jumbled #81140

Closed
GPHemsley mannequin opened this issue May 18, 2019 · 8 comments
Closed

ISO date errors in _strptime are jumbled #81140

GPHemsley mannequin opened this issue May 18, 2019 · 8 comments
Labels
3.11 only security fixes 3.12 bugs and security fixes 3.13 new features, bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@GPHemsley
Copy link
Mannequin

GPHemsley mannequin commented May 18, 2019

BPO 36959
Nosy @pganssle, @GPHemsley
PRs
  • bpo-36959: Fix checks for invalid ISO date formats in _strptime #13408
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2019-05-18.19:46:43.829>
    labels = ['tests', '3.8', 'library']
    title = 'ISO date errors in _strptime are jumbled'
    updated_at = <Date 2019-05-19.01:10:45.613>
    user = 'https://github.com/GPHemsley'

    bugs.python.org fields:

    activity = <Date 2019-05-19.01:10:45.613>
    actor = 'gphemsley'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)', 'Tests']
    creation = <Date 2019-05-18.19:46:43.829>
    creator = 'gphemsley'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 36959
    keywords = ['patch']
    message_count = 5.0
    messages = ['342810', '342811', '342812', '342816', '342828']
    nosy_count = 2.0
    nosy_names = ['p-ganssle', 'gphemsley']
    pr_nums = ['13408']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue36959'
    versions = ['Python 3.8']

    @GPHemsley
    Copy link
    Mannequin Author

    GPHemsley mannequin commented May 18, 2019

    This has not been apparent because the tests for this code are not testing what they think they're testing.

    @GPHemsley GPHemsley mannequin added 3.8 only security fixes stdlib Python modules in the Lib dir tests Tests in the Lib/test dir labels May 18, 2019
    @pganssle
    Copy link
    Member

    @gphelmsley Can you clarify what you mean by this?

    Do you have a minimal reproducing example that shows what's happening and what you are expecting?

    @GPHemsley
    Copy link
    Mannequin Author

    GPHemsley mannequin commented May 18, 2019

    I've created a PR that fixes the issue, which I discovered while evaluating the test coverage for _strptime.

    Certain scenarios of error messages were never being hit because the cascade was out of order, and the tests were not showing that because they were throwing a different ValueError than the one they were expecting to throw.

    @pganssle
    Copy link
    Member

    Hm, I was a bit confused by your wording here, because I am able to trigger all the errors just fine even before this PR, but I do think that even though this isn't necessarily fixing inaccurate error messages (all the error messages *are* accurate), you're right that the text of the messages does seem to indicate that the original authors intended a cascade ordering more like the one you've proposed.

    I'll give this a more thorough review a bit later, thanks for working on this!

    @GPHemsley
    Copy link
    Mannequin Author

    GPHemsley mannequin commented May 19, 2019

    Ah yes, to be clear, I wasn't trying to suggest that the error messages themselves were wrong—just that they weren't triggering when the tests were expecting them to.

    Some of the existing tests currently trigger the "unconverted data remains" ValueError from earlier in the method, but because the messages are not checked, that is not immediately obvious. I've also added new tests for additional scenarios that would presumably also be considered invalid, based on the existing ones.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @serhiy-storchaka
    Copy link
    Member

    There are two changes in test results:

    _strptime('1999 256', '%G %j'):
    was "ISO year directive '%G' must be used with the ISO week directive '%V' and a weekday directive ('%A', '%a', '%w', or '%u')."
    proposed "Day of the year directive '%j' is not compatible with ISO year directive '%G'. Use '%Y' instead."

    _strptime('50 5', '%V %u'):
    was "ISO week directive '%V' is incompatible with the year directive '%Y'. Use the ISO year '%G' instead."
    proposed "ISO week directive '%V' must be used with the ISO year directive '%G' and a weekday directive ('%A', '%a', '%w', or '%u')."

    In both cases the former message refers to a directive that does not appear in the format string.

    @serhiy-storchaka serhiy-storchaka added type-bug An unexpected behavior, bug, or error 3.11 only security fixes 3.12 bugs and security fixes 3.13 new features, bugs and security fixes and removed 3.8 only security fixes tests Tests in the Lib/test dir labels Dec 26, 2023
    @serhiy-storchaka
    Copy link
    Member

    I consider this as a bug.

    @serhiy-storchaka
    Copy link
    Member

    Thank you for your contribution @GPHemsley. Sorry for the delay.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.11 only security fixes 3.12 bugs and security fixes 3.13 new features, bugs and security fixes stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    Archived in project
    Development

    No branches or pull requests

    2 participants