nebius/SWE-bench-extra huggingface dataset:
Repository: m0nhawk/grafana_api

Issue:
Missing timeouts
**Describe the bug**
The requests never timeout, this is not a good idea in general

**Expected behavior**
The user should be able to set one and there should be a default (maybe 10s)

Comments:

Patch:
diff --git a/grafana_api/grafana_api.py b/grafana_api/grafana_api.py
index e965768..bb7cc5e 100644
--- a/grafana_api/grafana_api.py
+++ b/grafana_api/grafana_api.py
@@ -56,9 +56,11 @@ class GrafanaAPI:
         url_path_prefix="",
         protocol="http",
         verify=True,
+        timeout=5.0,
     ):
         self.auth = auth
         self.verify = verify
+        self.timeout = timeout
         self.url_host = host
         self.url_port = port
         self.url_path_prefix = url_path_prefix
@@ -92,7 +94,7 @@ class GrafanaAPI:
             __url = "%s%s" % (self.url, url)
             runner = getattr(self.s, item.lower())
             r = runner(
-                __url, json=json, headers=headers, auth=self.auth, verify=self.verify
+                __url, json=json, headers=headers, auth=self.auth, verify=self.verify, timeout=self.timeout
             )
             if 500 <= r.status_code < 600:
                 raise GrafanaServerError(
diff --git a/grafana_api/grafana_face.py b/grafana_api/grafana_face.py
index dcc8667..f9fe53b 100644
--- a/grafana_api/grafana_face.py
+++ b/grafana_api/grafana_face.py
@@ -24,6 +24,7 @@ class GrafanaFace:
         url_path_prefix="",
         protocol="http",
         verify=True,
+        timeout=5.0,
     ):
         self.api = GrafanaAPI(
             auth,
@@ -32,6 +33,7 @@ class GrafanaFace:
             url_path_prefix=url_path_prefix,
             protocol=protocol,
             verify=verify,
+            timeout=timeout,
         )
         self.admin = Admin(self.api)
         self.dashboard = Dashboard(self.api)


Test patch:
diff --git a/test/test_grafana.py b/test/test_grafana.py
index d4affad..1c8ede3 100644
--- a/test/test_grafana.py
+++ b/test/test_grafana.py
@@ -67,8 +67,22 @@ class TestGrafanaAPI(unittest.TestCase):
             headers=None,
             json=None,
             verify=False,
+            timeout=5.0,
         )
 
+    def test_grafana_api_timeout(self):
+        cli = GrafanaFace(
+            ("admin", "admin"),
+            host="play.grafana.org",
+            url_path_prefix="",
+            protocol="https",
+            verify=False,
+            timeout=0.0001
+        )
+
+        with self.assertRaises(requests.exceptions.Timeout):
+            cli.folder.get_all_folders()
+
     def test_grafana_api_basic_auth(self):
         cli = GrafanaFace(
             ("admin", "admin"), host="localhost", url_path_prefix="", protocol="https",port="3000"
Repository: macbre/sql-metadata

Issue:
Issue with table extraction for delete and drop query type
hi, 

Do you know why or when the above query type (delete, drop) should be supported? Or why it's not supported by now?

thanks.

Comments:

Patch:
diff --git a/sql_metadata/keywords_lists.py b/sql_metadata/keywords_lists.py
index b20e12d..3414f1c 100644
--- a/sql_metadata/keywords_lists.py
+++ b/sql_metadata/keywords_lists.py
@@ -76,6 +76,7 @@ class QueryType(str, Enum):
     SELECT = "SELECT"
     CREATE = "CREATE TABLE"
     ALTER = "ALTER TABLE"
+    DROP = "DROP TABLE"
 
 
 class TokenType(str, Enum):
@@ -102,6 +103,7 @@ SUPPORTED_QUERY_TYPES = {
     "WITH": QueryType.SELECT,
     "CREATETABLE": QueryType.CREATE,
     "ALTERTABLE": QueryType.ALTER,
+    "DROPTABLE": QueryType.DROP,
 }
 
 # all the keywords we care for - rest is ignored in assigning
diff --git a/sql_metadata/parser.py b/sql_metadata/parser.py
index 03f72d8..d4fd473 100644
--- a/sql_metadata/parser.py
+++ b/sql_metadata/parser.py
@@ -112,7 +112,7 @@ class Parser:  # pylint: disable=R0902
             )
             .position
         )
-        if tokens[index].normalized in ["CREATE", "ALTER"]:
+        if tokens[index].normalized in ["CREATE", "ALTER", "DROP"]:
             switch = tokens[index].normalized + tokens[index + 1].normalized
         else:
             switch = tokens[index].normalized


Test patch:
diff --git a/test/test_drop_table.py b/test/test_drop_table.py
new file mode 100644
index 0000000..8764020
--- /dev/null
+++ b/test/test_drop_table.py
@@ -0,0 +1,9 @@
+from sql_metadata import Parser
+from sql_metadata.keywords_lists import QueryType
+
+
+def test_drop_table():
+    parser = Parser("DROP TABLE foo")
+    assert parser.query_type == QueryType.DROP
+    assert parser.tables == ["foo"]
+    assert parser.columns == []
diff --git a/test/test_query_type.py b/test/test_query_type.py
index 15f9fae..44b8f33 100644
--- a/test/test_query_type.py
+++ b/test/test_query_type.py
@@ -38,6 +38,16 @@ def test_delete_query():
             assert "DELETE" == Parser(query.format(comment)).query_type
 
 
+def test_drop_table_query():
+    queries = [
+        "{0}DROP TABLE foo;{0}",
+    ]
+
+    for query in queries:
+        for comment in ["", "/* foo */", "\n--foo\n", "\n# foo\n"]:
+            assert "DROP TABLE" == Parser(query.format(comment)).query_type
+
+
 def test_unsupported_query():
     queries = [
         "FOO BAR",
Repository: macbre/sql-metadata

Issue:
limit_and_offset method bug?
example query:
sqltext = Parser("SELECT count(*) FROM aa WHERE grad = 88038 AND userid in(222,333) AND type = 1 AND checkable = 'sea'  LIMIT 50 OFFSET 1000").limit_and_offset

actually result(wrong):
(333, 1000)

Expected result
(50, 1000)



Comments:

Patch:
diff --git a/sql_metadata/parser.py b/sql_metadata/parser.py
index ab0a8fc..349f044 100644
--- a/sql_metadata/parser.py
+++ b/sql_metadata/parser.py
@@ -382,8 +382,12 @@ class Parser:  # pylint: disable=R0902
                 elif token.last_keyword_normalized == "OFFSET":
                     # OFFSET <offset>
                     offset = int(token.value)
-                elif token.previous_token.is_punctuation:
+                elif (
+                    token.previous_token.is_punctuation
+                    and token.last_keyword_normalized == "LIMIT"
+                ):
                     # LIMIT <offset>,<limit>
+                    #  enter this condition only when the limit has already been parsed
                     offset = limit
                     limit = int(token.value)
 


Test patch:
diff --git a/test/test_limit_and_offset.py b/test/test_limit_and_offset.py
index 024e935..1fd6aae 100644
--- a/test/test_limit_and_offset.py
+++ b/test/test_limit_and_offset.py
@@ -45,3 +45,10 @@ def test_comma_separated():
         "WHERE cl_type = 'page' AND cl_to = 'Spotify/Song'  "
         "ORDER BY cl_sortkey LIMIT 927600,200"
     ).limit_and_offset == (200, 927600)
+
+
+def test_with_in_condition():
+    # https://github.com/macbre/sql-metadata/issues/382
+    assert Parser(
+        "SELECT count(*) FROM aa WHERE userid IN (222,333) LIMIT 50 OFFSET 1000"
+    ).limit_and_offset == (50, 1000)
Repository: macbre/sql-metadata

Issue:
Can not handle correctly with mysql upsert statement
```sql
insert into user (id, name, age) 
  values ('user1', 'john doe', 20) 
  on duplicate key 
  update name='john doe', age=20;
```

The correct value of `Parser(sql).tables` is `['user']`, but it returns `['user', 'name', 'age']`.

I used `0.4.3`.

Comments:

Patch:
diff --git a/sql_metadata/parser.py b/sql_metadata/parser.py
index 349f044..c422846 100644
--- a/sql_metadata/parser.py
+++ b/sql_metadata/parser.py
@@ -357,6 +357,14 @@ class Parser:  # pylint: disable=R0902
                     )
                 ):
                     continue
+
+                # handle INSERT INTO ON DUPLICATE KEY UPDATE queries
+                if (
+                    token.last_keyword_normalized == "UPDATE"
+                    and self.query_type == "INSERT"
+                ):
+                    continue
+
                 table_name = str(token.value.strip("`"))
                 token.token_type = TokenType.TABLE
                 tables.append(table_name)


Test patch:
diff --git a/test/test_getting_tables.py b/test/test_getting_tables.py
index 76c8741..d90b0ce 100644
--- a/test/test_getting_tables.py
+++ b/test/test_getting_tables.py
@@ -658,3 +658,11 @@ def test_cross_join_with_subquery():
     assert parser.subqueries == {
         "foobar": "SELECT * FROM bars",
     }
+
+
+def test_insert_into_on_duplicate_key_ipdate():
+    assert Parser(
+        "INSERT INTO user (id, name, age)"
+        " VALUES ('user1', 'john doe', 20)"
+        " ON DUPLICATE KEY UPDATE name='john doe', age=20"
+    ).tables == ["user"]