Skip to content

V2.1.2 more bug fixes #47

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

Merged
merged 6 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
**2025-05-19: Bug fixes for iter_cursor and HTTP 204 response handling**

* Allow ``try_decoding`` to return ``None`` for empty input; fixes GitHub issue #46.
* Non-breaking changes to ``RestApiV2Client.iter_cursor``, to fix GitHub issue #45:

- It now uses the ``default_page_size`` client setting as the ``limit`` parameter.
- It accepts a ``page_size`` parameter that can override said default (and ``params`` can also override this default), similar to ``iter_all``.
- When called indirectly via ``iter_all``, the ``item_hook`` keyword argument is passed through to it, along with ``page_size``.

**2025-05-14: Bug fix - Version 2.1.1**

* The "main" method in the entry script is expected to receive no arguments, but in v2.1.0, it requires one positional argument.

**2025-05-13: Command line interface - Version 2.1.0**

* Add a basic command line interface for Events API v2, for feature parity with the legacy library that is used in the `Monit Integration Guide <https://www.pagerduty.com/docs/guides/monit-integration-guide/>`_.

**2025-04-08: Multi-file refactor - Version 2.0.0**

This release introduces major structural changes to the module and how it is built and tested. These changes were made for long-term maintainability of the codebase. Previously, it was all contained within a monolithic ``.py`` file (with a single Python script for all unit tests); now it is organized into smaller, appropriately-named Python files.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
build: pagerduty/* pyproject.toml
rm -f dist/* && python3 -m build

docs/index.html: pagerduty/* README.rst CHANGELOG.rst sphinx/source/*
docs/index.html: build pyproject.toml pagerduty/* CHANGELOG.rst sphinx/source/*
rm -fr ./docs && cd sphinx && make html && cd .. && mv sphinx/build/html ./docs && touch ./docs/.nojekyll

docs: docs/index.html pagerduty/__pycache__
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ This library is available on the Python Package Index as `pagerduty <https://pyp

Command Line Interface
----------------------
This package also includes a basic CLI for triggering incidents using the
PagerDuty Events API V2. For example, to trigger an incident:
This package also includes a basic CLI for PagerDuty Events API V2. For
example, to trigger an incident:

.. code-block:: bash

Expand Down
2 changes: 1 addition & 1 deletion docs/_static/documentation_options.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const DOCUMENTATION_OPTIONS = {
VERSION: '2.1.0',
VERSION: '2.1.2',
LANGUAGE: 'en',
COLLAPSE_INDEX: false,
BUILDER: 'html',
Expand Down
25 changes: 23 additions & 2 deletions docs/changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Changelog &mdash; python-pagerduty 2.1.0 documentation</title>
<title>Changelog &mdash; python-pagerduty 2.1.2 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=03e43079" />
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=e59714d7" />


<script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=20623aea"></script>
<script src="_static/documentation_options.js?v=b3e23499"></script>
<script src="_static/doctools.js?v=9bcbadda"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/js/theme.js"></script>
Expand Down Expand Up @@ -76,6 +76,27 @@

<section id="changelog">
<h1>Changelog<a class="headerlink" href="#changelog" title="Link to this heading"></a></h1>
<p><strong>2025-05-19: Bug fixes for iter_cursor and HTTP 204 response handling</strong></p>
<ul>
<li><p>Allow <code class="docutils literal notranslate"><span class="pre">try_decoding</span></code> to return <code class="docutils literal notranslate"><span class="pre">None</span></code> for empty input; fixes GitHub issue #46.</p></li>
<li><p>Non-breaking changes to <code class="docutils literal notranslate"><span class="pre">RestApiV2Client.iter_cursor</span></code>, to fix GitHub issue #45:</p>
<blockquote>
<div><ul class="simple">
<li><p>It now uses the <code class="docutils literal notranslate"><span class="pre">default_page_size</span></code> client setting as the <code class="docutils literal notranslate"><span class="pre">limit</span></code> parameter.</p></li>
<li><p>It accepts a <code class="docutils literal notranslate"><span class="pre">page_size</span></code> parameter that can override said default (and <code class="docutils literal notranslate"><span class="pre">params</span></code> can also override this default), similar to <code class="docutils literal notranslate"><span class="pre">iter_all</span></code>.</p></li>
<li><p>When called indirectly via <code class="docutils literal notranslate"><span class="pre">iter_all</span></code>, the <code class="docutils literal notranslate"><span class="pre">item_hook</span></code> keyword argument is passed through to it, along with <code class="docutils literal notranslate"><span class="pre">page_size</span></code>.</p></li>
</ul>
</div></blockquote>
</li>
</ul>
<p><strong>2025-05-14: Bug fix - Version 2.1.1</strong></p>
<ul class="simple">
<li><p>The “main” method in the entry script is expected to receive no arguments, but in v2.1.0, it requires one positional argument.</p></li>
</ul>
<p><strong>2025-05-13: Command line interface - Version 2.1.0</strong></p>
<ul class="simple">
<li><p>Add a basic command line interface for Events API v2, for feature parity with the legacy library that is used in the <a class="reference external" href="https://www.pagerduty.com/docs/guides/monit-integration-guide/">Monit Integration Guide</a>.</p></li>
</ul>
<p><strong>2025-04-08: Multi-file refactor - Version 2.0.0</strong></p>
<p>This release introduces major structural changes to the module and how it is built and tested. These changes were made for long-term maintainability of the codebase. Previously, it was all contained within a monolithic <code class="docutils literal notranslate"><span class="pre">.py</span></code> file (with a single Python script for all unit tests); now it is organized into smaller, appropriately-named Python files.</p>
<p>Some lesser changes are also included:</p>
Expand Down
4 changes: 2 additions & 2 deletions docs/contributing.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Contribution Guide &mdash; python-pagerduty 2.1.0 documentation</title>
<title>Contribution Guide &mdash; python-pagerduty 2.1.2 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=03e43079" />
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=e59714d7" />


<script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=20623aea"></script>
<script src="_static/documentation_options.js?v=b3e23499"></script>
<script src="_static/doctools.js?v=9bcbadda"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/js/theme.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions docs/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Index &mdash; python-pagerduty 2.1.0 documentation</title>
<title>Index &mdash; python-pagerduty 2.1.2 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=03e43079" />
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=e59714d7" />


<script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=20623aea"></script>
<script src="_static/documentation_options.js?v=b3e23499"></script>
<script src="_static/doctools.js?v=9bcbadda"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/js/theme.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>python-pagerduty: Clients for PagerDuty’s APIs &mdash; python-pagerduty 2.1.0 documentation</title>
<title>python-pagerduty: Clients for PagerDuty’s APIs &mdash; python-pagerduty 2.1.2 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=03e43079" />
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=e59714d7" />


<script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=20623aea"></script>
<script src="_static/documentation_options.js?v=b3e23499"></script>
<script src="_static/doctools.js?v=9bcbadda"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/js/theme.js"></script>
Expand Down
8 changes: 5 additions & 3 deletions docs/module_reference.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Module Reference &mdash; python-pagerduty 2.1.0 documentation</title>
<title>Module Reference &mdash; python-pagerduty 2.1.2 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=03e43079" />
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=e59714d7" />


<script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=20623aea"></script>
<script src="_static/documentation_options.js?v=b3e23499"></script>
<script src="_static/doctools.js?v=9bcbadda"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/js/theme.js"></script>
Expand Down Expand Up @@ -615,7 +615,7 @@ <h2>API Client Classes<a class="headerlink" href="#api-client-classes" title="Li

<dl class="py method">
<dt class="sig sig-object py" id="pagerduty.RestApiV2Client.iter_cursor">
<span class="sig-name descname"><span class="pre">iter_cursor</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">url</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">params</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">item_hook</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">Iterator</span><span class="p"><span class="pre">[</span></span><span class="pre">dict</span><span class="p"><span class="pre">]</span></span></span></span><a class="headerlink" href="#pagerduty.RestApiV2Client.iter_cursor" title="Link to this definition"></a></dt>
<span class="sig-name descname"><span class="pre">iter_cursor</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">url</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">params</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">item_hook</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">page_size</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">Iterator</span><span class="p"><span class="pre">[</span></span><span class="pre">dict</span><span class="p"><span class="pre">]</span></span></span></span><a class="headerlink" href="#pagerduty.RestApiV2Client.iter_cursor" title="Link to this definition"></a></dt>
<dd><p>Iterator for results from an endpoint using cursor-based pagination.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
Expand All @@ -624,6 +624,8 @@ <h2>API Client Classes<a class="headerlink" href="#api-client-classes" title="Li
<li><p><strong>params</strong> – Query parameters to include in the request.</p></li>
<li><p><strong>item_hook</strong> – A callable object that accepts 3 positional arguments; see <a class="reference internal" href="#pagerduty.RestApiV2Client.iter_all" title="pagerduty.RestApiV2Client.iter_all"><code class="xref py py-attr docutils literal notranslate"><span class="pre">iter_all</span></code></a>
for details on how this argument is used.</p></li>
<li><p><strong>page_size</strong> – Number of results per page of results (the <code class="docutils literal notranslate"><span class="pre">limit</span></code> parameter). If
unspecified, <a class="reference internal" href="#pagerduty.RestApiV2Client.default_page_size" title="pagerduty.RestApiV2Client.default_page_size"><code class="xref py py-attr docutils literal notranslate"><span class="pre">default_page_size</span></code></a> will be used.</p></li>
</ul>
</dd>
</dl>
Expand Down
Binary file modified docs/objects.inv
Binary file not shown.
4 changes: 2 additions & 2 deletions docs/pdpyras_migration_guide.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PDPYRAS Migration Guide &mdash; python-pagerduty 2.1.0 documentation</title>
<title>PDPYRAS Migration Guide &mdash; python-pagerduty 2.1.2 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=03e43079" />
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=e59714d7" />


<script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=20623aea"></script>
<script src="_static/documentation_options.js?v=b3e23499"></script>
<script src="_static/doctools.js?v=9bcbadda"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/js/theme.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions docs/py-modindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Python Module Index &mdash; python-pagerduty 2.1.0 documentation</title>
<title>Python Module Index &mdash; python-pagerduty 2.1.2 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=03e43079" />
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=e59714d7" />


<script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=20623aea"></script>
<script src="_static/documentation_options.js?v=b3e23499"></script>
<script src="_static/doctools.js?v=9bcbadda"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/js/theme.js"></script>
Expand Down
4 changes: 2 additions & 2 deletions docs/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Search &mdash; python-pagerduty 2.1.0 documentation</title>
<title>Search &mdash; python-pagerduty 2.1.2 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=03e43079" />
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=e59714d7" />



<script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=20623aea"></script>
<script src="_static/documentation_options.js?v=b3e23499"></script>
<script src="_static/doctools.js?v=9bcbadda"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/js/theme.js"></script>
Expand Down
2 changes: 1 addition & 1 deletion docs/searchindex.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/user_guide.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
<meta charset="utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>User Guide &mdash; python-pagerduty 2.1.0 documentation</title>
<title>User Guide &mdash; python-pagerduty 2.1.2 documentation</title>
<link rel="stylesheet" type="text/css" href="_static/pygments.css?v=03e43079" />
<link rel="stylesheet" type="text/css" href="_static/css/theme.css?v=e59714d7" />


<script src="_static/jquery.js?v=5d32c60e"></script>
<script src="_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="_static/documentation_options.js?v=20623aea"></script>
<script src="_static/documentation_options.js?v=b3e23499"></script>
<script src="_static/doctools.js?v=9bcbadda"></script>
<script src="_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="_static/js/theme.js"></script>
Expand Down Expand Up @@ -131,8 +131,8 @@ <h2>Installation<a class="headerlink" href="#installation" title="Link to this h
</section>
<section id="command-line-interface">
<h2>Command Line Interface<a class="headerlink" href="#command-line-interface" title="Link to this heading"></a></h2>
<p>This package also includes a basic CLI for triggering incidents using the
PagerDuty Events API V2. For example, to trigger an incident:</p>
<p>This package also includes a basic CLI for PagerDuty Events API V2. For
example, to trigger an incident:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>pagerduty<span class="w"> </span>trigger<span class="w"> </span>-k<span class="w"> </span><span class="nv">$ROUTING_KEY</span><span class="w"> </span>--description<span class="w"> </span><span class="s2">&quot;Network latency is high&quot;</span>
</pre></div>
</div>
Expand Down
16 changes: 11 additions & 5 deletions pagerduty/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
from typing import Union
from warnings import warn

from json.decoder import JSONDecodeError

# PyPI
from requests import Response

Expand Down Expand Up @@ -164,8 +166,12 @@ def try_decoding(r: Response) -> Union[dict, list, str]:
"""
try:
return r.json()
except ValueError as e:
raise ServerHttpError(
"API responded with invalid JSON: " + truncate_text(r.text),
r,
)
except (JSONDecodeError, ValueError) as e:
if r.text.strip() == '':
# Some endpoints return HTTP 204 for request types other than delete
return None
else:
raise ServerHttpError(
"API responded with invalid JSON: " + truncate_text(r.text),
r,
)
Loading