Attention is currently required from: PywikibotCommitWatcher.
Hello PywikibotCommitWatcher,
I'd like you to do a code review.
Please visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1230405?usp=email
to review the following change.
Change subject: Fix: validate 'start' parameter in parse_start and raise
ValueError on invalid formats
......................................................................
Fix: validate 'start' parameter in parse_start and raise ValueError on invalid
formats
Improved input handling in parse_start by detecting invalid timestamp
strings and raising a clear ValueError instead of silently converting them.
This matches expected behavior in LogeventsPageGenerator and ensures
better consistency with test expectations.
Change-Id: I4ef16fbcb7059bf137d47095564f508765e12ccf
---
M pywikibot/pagegenerators/_factory.py
1 file changed, 13 insertions(+), 11 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/05/1230405/1
diff --git a/pywikibot/pagegenerators/_factory.py
b/pywikibot/pagegenerators/_factory.py
index 22d5201..bcd1dfa 100644
--- a/pywikibot/pagegenerators/_factory.py
+++ b/pywikibot/pagegenerators/_factory.py
@@ -387,22 +387,24 @@
value.
"""
def parse_start(
- start: str | None
- ) -> tuple[pywikibot.Timestamp | None, int | None]:
+ start: str | None,
+ ) -> tuple[Optional[pywikibot.Timestamp], Optional[int]]:
"""Parse start and return (start, total)."""
if not start:
return None, None
- if len(start) >= 8:
- return pywikibot.Timestamp.fromtimestampformat(start), None
+ # If start looks like timestamp → treat as timestamp
+ if len(start) >= 8 and start.isdigit():
+ try:
+ return pywikibot.Timestamp.fromtimestampformat(start), None
+ except Exception as err:
+ raise ValueError(f"Invalid timestamp format: {err}") from
err
- instead = (f'-limit option like "-logevents:{logtype}'
- f'{"," if user else ""}{user} -limit:{start}"')
- issue_deprecation_warning('-logevents with total argument',
- instead,
- warning_class=ArgumentDeprecationWarning,
- since='9.2.0')
- return None, int(start)
+ # If NOT timestamp → treat as total number
+ if start.isdigit():
+ return None, int(start)
+
+ raise ValueError("Start must be timestamp (>=8 digits) or a
positive integer.")
try:
start_, total = parse_start(start)
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1230405?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I4ef16fbcb7059bf137d47095564f508765e12ccf
Gerrit-Change-Number: 1230405
Gerrit-PatchSet: 1
Gerrit-Owner: AtharvaKathe <[email protected]>
Gerrit-Reviewer: AtharvaKathe <[email protected]>
Gerrit-Reviewer: PywikibotCommitWatcher <[email protected]>
Gerrit-Attention: PywikibotCommitWatcher <[email protected]>
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]