EnAccess / EnAccess/OpenPAYGO-python

[Bug]: Inconsistent `value` behaviour between `generate_token` and `decode_token` for `DISABLE_PAYG` and `COUNTER_SYNC`

オープン
#25 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug
主要言語
Python
スター
15
フォーク
15
PR マージ指標
30日以内にマージされた PR はありません

説明

### Preflight Checklist

- [x] I have read the [Contributing Guidelines](https://github.com/EnAccess/OpenPAYGO-python/blob/main/CONTRIBUTING.md) for this project, if it exists.
- [x] I agree to follow the [Code of Conduct](https://github.com/EnAccess/OpenPAYGO-python/blob/main/CODE_OF_CONDUCT.md) that this project adheres to.
- [x] I have searched the [issue tracker](https://github.com/EnAccess/OpenPAYGO-python/issues) for a feature request that matches the one I want to file, without success.

### Expected Behavior

Token value and Token Type have a 1:1 relation for `DISABLE_PAYG` and `COUNTER_SYNC`. As a user I would expect `generate_token` and `decode_token` to have the same interface in terms of how `DISABLE_PAYG` and `COUNTER_SYNC` are specified.

### Actual Behavior

In **generate_token** only `token_type` must be specified. Providing a non-`None` value yields:

```sh
ValueError: A value is not allowed for this token type.
```

In **decode_token** both `token_type` and `token_value` are returned.

### Steps to reproduce

```python
# OpenPAYGO-python
from openpaygo import OpenPAYGOTokenEncoder, TokenType

encoder = OpenPAYGOTokenEncoder()

new_count, final_token = encoder.generate_token(
secret_key="bc41ec9530f6dac86b1a29ab82edc5fb",
count=4,
value=998,
token_type=TokenType.DISABLE_PAYG,
starting_code=516959010,
restricted_digit_set=False,
extended_token=False,
)

print(f"{new_count=}")
print(f"{final_token=}")
```

### What operating system(s) are you using?

macOS

### Additional Information

**Suggested solutions:**

Change `generate_token` to allow a token value that matches the provided token type. If none is given, the token value is derived from token_type. If a token type is provided that does not match the token value throw an error explaining the problem.

**Alternative solution:**

Change `decode_token` to not return token values for `DISABLE_PAYG` and `COUNTER_SYNC`

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

まず、OpenPAYGO-python パッケージ内の generate_token と decode_token のエントリーポイントを見つけ、提供されている DISABLE_PAYG の例を再現します。token_type と token_value がどのように受け付けられ、返されるかを比較し、提案された解決策の中から意図された一貫性のある契約を選択します。両方のインターフェースがこれらのトークン型を一貫して処理すれば、issue は完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
api
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。