Skip to content

Commit

Permalink
fix: 'str' object has no attribute 'removesuffix' in Python 3.8 (#950)
Browse files Browse the repository at this point in the history
* fix suffix api issue

Signed-off-by: Ahmad Wahid <ahmedwahid16101@gmail.com>

* update changelog

Signed-off-by: Ahmad Wahid <ahmedwahid16101@gmail.com>

* docs: move changelog entry to 0.18.1

Signed-off-by: F.N. Claessen <felix@seita.nl>

---------

Signed-off-by: Ahmad Wahid <ahmedwahid16101@gmail.com>
Signed-off-by: F.N. Claessen <felix@seita.nl>
Co-authored-by: F.N. Claessen <felix@seita.nl>
  • Loading branch information
Ahmad-Wahid and Flix6x committed Jan 8, 2024
1 parent a0ad431 commit 2bab4b3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
3 changes: 2 additions & 1 deletion documentation/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Bugfixes

* Allow showing beliefs (plot and file export) via the CLI for sensors with non-unique names [see `PR #947 <https://github.com/FlexMeasures/flexmeasures/pull/947>`_]
* Added Redis credentials to the Docker Compose configuration for the web server to ensure proper interaction with the Redis queue [see `PR #945 <https://github.com/FlexMeasures/flexmeasures/pull/945>`_]
* Fix API version listing (GET /api/v3_0) for hosts running on Python 3.8 [see `PR #917 <https://github.com/FlexMeasures/flexmeasures/pull/917>`_ and `PR #950 <https://github.com/FlexMeasures/flexmeasures/pull/950>`_]


v0.18.0 | December 23, 2023
Expand Down Expand Up @@ -72,7 +73,7 @@ Bugfixes
* Show `Assets`, `Users`, `Tasks` and `Accounts` pages in the navigation bar for the `admin-reader` role [see `PR #900 <https://github.com/FlexMeasures/flexmeasures/pull/900>`_]
* Reduce worker logs when datetime exceeds the end of the schedule [see `PR #918 <https://github.com/FlexMeasures/flexmeasures/pull/918>`_]
* Fix infeasible problem due to incorrect estimation of the big-M value [see `PR #905 <https://github.com/FlexMeasures/flexmeasures/pull/905>`_]
* Fix API version listing (GET /api/v3_0) for hosts running on Python 3.8 [see `PR #917 <https://github.com/FlexMeasures/flexmeasures/pull/917>`_]
* [Incomplete fix; full fix in v0.18.1] Fix API version listing (GET /api/v3_0) for hosts running on Python 3.8 [see `PR #917 <https://github.com/FlexMeasures/flexmeasures/pull/917>`_]


v0.17.0 | November 8, 2023
Expand Down
14 changes: 13 additions & 1 deletion flexmeasures/api/v3_0/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def index(self):
)
stripped_url = removeprefix(url, self.route_base)
full_url = (
request.url_root.removesuffix("/") + url
removesuffix(request.url_root, "/") + url
if url.startswith("/")
else request.url_root + url
)
Expand Down Expand Up @@ -87,3 +87,15 @@ def removeprefix(text: str, prefix: str) -> str:
return text[len(prefix) :]
else:
return text


def removesuffix(text: str, suffix: str) -> str:
"""Remove a suffix from a text.
todo: use text.removesuffix(suffix) instead of this method, after dropping support for Python 3.8
See https://docs.python.org/3.9/library/stdtypes.html#str.removesuffix
"""
if text.endswith(suffix):
return text[: -len(suffix)]
else:
return text

0 comments on commit 2bab4b3

Please sign in to comment.