Merge lp:~jcsackett/launchpad/dumb-date-formats into lp:launchpad
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | j.c.sackett | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | 12434 | ||||
Proposed branch: | lp:~jcsackett/launchpad/dumb-date-formats | ||||
Merge into: | lp:launchpad | ||||
Diff against target: |
129 lines (+85/-1) 2 files modified
lib/lp/app/widgets/date.py (+41/-1) lib/lp/app/widgets/tests/test_datetime.py (+44/-0) |
||||
To merge this branch: | bzr merge lp:~jcsackett/launchpad/dumb-date-formats | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Benji York (community) | code | Approve | |
Review via email: mp+50385@code.launchpad.net |
Commit message
[r=benji][bug=134063] Updates DateTime widget to kick back formats it can't possibly cope with.
Description of the change
Summary
=======
On the new sprint page, an OOPS can be triggered when dates that zope.date.parse can't understand get entered. Rather than throwing back an error, parse munges the dates into a format it can deal with, resulting in data that throws of db constraints.
This branch updates the widget to check if the date string is in any supported format, and kicks back an error message (rather than an OOPS) if it isn't.
Preimplementation
=================
Spoke with Curtis Hovey
Proposed Fix
============
Update the widget so it kicks back the input *before* the widget converts it into an erroneous datetime object.
Implementation
==============
The DateTimeWidget in lp.apps.
It also has a new method, _checkSupported
Tests
=====
bin/test -m lp.app.
Demo & QA
=========
Try to enter the dates listed in the bug; they should come back with errors, rather than triggering an OOPS.
Lint
=====
make lint output:
= Launchpad lint =
Checking for conflicts and issues in changed files.
Linting changed files:
lib/lp/
This branch looks good. A few things to consider:
Deepening on the text of an exception message can be dangerous. Most
libraries don't consider them to be part of the API, so they may change
without warning. I would add a small test that ensures that the text
you expect ("unconverted data remains") is generated when you expect it
to be. That way if different text gets generated later we'll have a
test specifically about that fail instead of a hard to diagnose edge
case failure.
If that particular behavior had been in an upstream library and not the
Python stdlib, I would have suggested promoting a patch to the library
to raise two different exceptions so you wouldn't have to check the
message. However, given Python's (long) release cycle and the immanent
end of Python 2 releases, I wouldn't bother.
Also, trailing whitespace triggers the "unconverted data remains"
message, so I believe entering a date in an unsupported format with
trailing whitespace will cause the input to be considered valid and
cause an OOPS when it gets deeper into the app.
Someone other than myself might want the new test be done as a unittest
instead of a doctest. Since you're only adding a small test to an
already large set of doctests, I think it's fine as-is.
Lastly, all the accepted formats requires seconds. Do we also want to
accept date/times without seconds?