launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #25892
[Merge] ~cjwatson/launchpad:py3-formattabledate into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:py3-formattabledate into launchpad:master.
Commit message:
Adjust FormattableDate to handle Python 3's date.strftime
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/395695
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-formattabledate into launchpad:master.
diff --git a/lib/lp/services/fields/__init__.py b/lib/lp/services/fields/__init__.py
index 9224282..5281d57 100644
--- a/lib/lp/services/fields/__init__.py
+++ b/lib/lp/services/fields/__init__.py
@@ -316,6 +316,14 @@ class FormattableDate(Date):
# As a minimal sanity check, just raise an error if it fails.
try:
value.strftime('%Y')
+ if value.year < 1900:
+ # Unlike Python 2, Python 3's `date.strftime` works fine on
+ # years earlier than 1900. However, we carry on refusing it
+ # anyway, partly for test compatibility and partly because
+ # at the time of writing this is only used for the targeted
+ # date of milestones and so dates before 1900 aren't
+ # interesting anyway.
+ raise ValueError('year=%d is before 1900' % value.year)
except ValueError:
raise LaunchpadValidationError(error_msg)