#4658 Support arrow >= 0.15.0
Merged 4 years ago by pingou. Opened 4 years ago by jlanda.
jlanda/pagure support-arrow-015  into  master

file modified
+2 -2
@@ -636,7 +636,7 @@ 

              try:

  

                  return arrow.get(d, tz).replace(hour=12).timestamp

-             except arrow.parser.ParserError:

+             except (arrow.parser.ParserError, ValueError):

                  # if tz is invalid for some reason, just go with UTC

                  return arrow.get(d).replace(hour=12).timestamp

          else:
@@ -727,7 +727,7 @@ 

      try:

          date = arrow.get(date)

          date = date.strftime("%Y-%m-%d")

-     except arrow.parser.ParserError as err:

+     except (arrow.parser.ParserError, ValueError) as err:

          raise pagure.exceptions.APIError(

              400, error_code=APIERROR.ENOCODE, error=str(err)

          )

file modified
+1 -1
@@ -1,7 +1,7 @@ 

  # Used for when working from a virtualenv.

  # Use this file by running "$ pip install -r requirements.txt"

  alembic

- arrow < 0.15.0

+ arrow

  bcrypt

  binaryornot

  bleach

file modified
+13
@@ -512,6 +512,19 @@ 

              wtforms_v[idx] = val

          return tuple(wtforms_v)

  

+     def get_arrow_version(self):

+         """ Returns the arrow version as a tuple."""

+         import arrow

+ 

+         arrow_v = arrow.__version__.split(".")

+         for idx, val in enumerate(arrow_v):

+             try:

+                 val = int(val)

+             except ValueError:

+                 pass

+             arrow_v[idx] = val

+         return tuple(arrow_v)

+ 

      def assertURLEqual(self, url_1, url_2):

          url_parsed_1 = list(urlparse(url_1))

          url_parsed_1[4] = parse_qs(url_parsed_1[4])

@@ -328,17 +328,38 @@ 

          output = self.app.get("/api/0/user/pingou/activity/AABB")

          self.assertEqual(output.status_code, 400)

  

-         # Invalid date

+         # Invalid date, arrow >= 0.15 throws an exception,

+         # previous versions parsed it

          output = self.app.get("/api/0/user/pingou/activity/2016asd")

-         self.assertEqual(output.status_code, 200)

-         exp = {"activities": [], "date": "2016-01-01"}

-         self.assertEqual(json.loads(output.get_data(as_text=True)), exp)

- 

-         # Date parsed, just not really as expected

+         if self.get_arrow_version() >= (0, 15):

+             self.assertEqual(output.status_code, 400)

+             exp = {

+                 "error": "Could not match input '2016asd' to any of the following formats: "

+                 "YYYY-MM-DD, YYYY-M-DD, YYYY-M-D, YYYY/MM/DD, YYYY/M/DD, YYYY/M/D, "

+                 "YYYY.MM.DD, YYYY.M.DD, YYYY.M.D, YYYYMMDD, YYYY-DDDD, YYYYDDDD, "

+                 "YYYY-MM, YYYY/MM, YYYY.MM, YYYY",

+                 "error_code": "ENOCODE",

+             }

+             self.assertEqual(json.loads(output.get_data(as_text=True)), exp)

+         else:

+             self.assertEqual(output.status_code, 200)

+             exp = {"activities": [], "date": "2016-01-01"}

+             self.assertEqual(json.loads(output.get_data(as_text=True)), exp)

+ 

+         # Invalid date, arrow => throws an exception,

+         # previous versions parsed it just not really as expected

          output = self.app.get("/api/0/user/pingou/activity/20161245")

-         self.assertEqual(output.status_code, 200)

-         exp = {"activities": [], "date": "1970-08-22"}

-         self.assertEqual(json.loads(output.get_data(as_text=True)), exp)

+         if self.get_arrow_version() >= (0, 15):

+             self.assertEqual(output.status_code, 400)

+             exp = {

+                 "error": "day is out of range for month",

+                 "error_code": "ENOCODE",

+             }

+             self.assertEqual(json.loads(output.get_data(as_text=True)), exp)

+         else:

+             self.assertEqual(output.status_code, 200)

+             exp = {"activities": [], "date": "1970-08-22"}

+             self.assertEqual(json.loads(output.get_data(as_text=True)), exp)

  

          date = datetime.datetime.utcnow().date().strftime("%Y-%m-%d")

          # Retrieve the user's logs for today

Fixes #4611

This should fix our tests, but I wanna check that we are capturing all the potential ValueError throws from arrow before merging this

rebased onto 3ef2feb5af6192c1c15ca256049a013075da71c4

4 years ago

1 new commit added

  • pagure/api/user: capture ValueError exception on arrow.get()
4 years ago

Okido, all the arrow.get that uses user provided strings as argument have a try catch block around them.

I did not add them on git|libgit2 provided times.

Let's rebase this but this is a way simpler diff than I expected, it's nice :)

Let's rebase this but this is a way simpler diff than I expected, it's nice :)

Yeah, I expected much more work too, but pagure-admin already has general catches around arrow.get()s and there are no so much of them on api|ui :)

rebased onto b1cfc82

4 years ago

Let's get this in! :)

Thanks for the patch!!

Pull-Request has been merged by pingou

4 years ago