Question: Detecting Misuse of Pytz Timezones in Python with CodeQL #848
Unanswered
ShreyTiwari
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello everyone,
I'm working on creating a CodeQL query to identify a specific code pattern in Python. My goal is to detect the misuse of Pytz timezones, particularly focusing on how
datetime
objects are created.Example of Misuse:
temp = pytz.timezone("US/Eastern")
dt2 = datetime(1, 1, 1, tzinfo=temp)
dt3 = datetime(1, 1, 1)
dt3 = dt3.replace(tzinfo=temp)
I want to flag the misuse occurring in lines 2 and 4 where the Pytz timezone object is applied incorrectly.
Query Attempt:
Here's the query I have written so far:
Issue:
The current implementation successfully detects the misuse on line 2 but fails to do so on line 4.
Request for Help:
Could someone help me identify what might be going wrong? Any pointers on debugging the CodeQL query or enhancing the current logic to detect the misuse in the
replace
call would be greatly appreciated.Thank you!
Beta Was this translation helpful? Give feedback.
All reactions