nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: cloudnativelabs/kube-router
Pull request #1713 (2024-08-06 20:09:16)

fix: select ICMP version for common ICMP rules
This fixes kube-router trying to use `icmp` instead of `icmpv6` when creating common ICMP rules with ip6tables.

Fixes: #1712

qbnit: Missed the tests the first time. Fixed now.
qbnit: Tests should all work now.

Patch:
diff --git a/pkg/utils/iptables.go b/pkg/utils/iptables.go
index 45cecdda..f1a5bc26 100644
--- a/pkg/utils/iptables.go
+++ b/pkg/utils/iptables.go
@@ -200,12 +200,22 @@ func (i *IPTablesSaveRestore) Restore(table string, data []byte) error {
 func CommonICMPRules(family v1core.IPFamily) []ICMPRule {
 	// Allow various types of ICMP that are important for routing
 	// This first block applies to both IPv4 and IPv6 type rules
+
+	var icmpProto, icmpType string
+	if family == v1core.IPv6Protocol {
+		icmpProto = ICMPv6Proto
+		icmpType = ICMPv6Type
+	} else {
+		icmpProto = ICMPv4Proto
+		icmpType = ICMPv4Type
+	}
+
 	icmpRules := []ICMPRule{
-		{ICMPv4Proto, ICMPv4Type, "echo-request", "allow icmp echo requests"},
+		{icmpProto, icmpType, "echo-request", "allow icmp echo requests"},
 		// destination-unreachable here is also responsible for handling / allowing PMTU
 		// (https://en.wikipedia.org/wiki/Path_MTU_Discovery) responses
-		{ICMPv4Proto, ICMPv4Type, "destination-unreachable", "allow icmp destination unreachable messages"},
-		{ICMPv4Proto, ICMPv4Type, "time-exceeded", "allow icmp time exceeded messages"},
+		{icmpProto, icmpType, "destination-unreachable", "allow icmp destination unreachable messages"},
+		{icmpProto, icmpType, "time-exceeded", "allow icmp time exceeded messages"},
 	}
 
 	if family == v1core.IPv6Protocol {


Test patch:
diff --git a/pkg/utils/iptables_test.go b/pkg/utils/iptables_test.go
index 96e55403..90ac6ba3 100644
--- a/pkg/utils/iptables_test.go
+++ b/pkg/utils/iptables_test.go
@@ -27,9 +27,9 @@ func TestCommonICMPRules(t *testing.T) {
 			name:   "IPv6",
 			family: v1core.IPv6Protocol,
 			expected: []ICMPRule{
-				{"icmp", "--icmp-type", "echo-request", "allow icmp echo requests"},
-				{"icmp", "--icmp-type", "destination-unreachable", "allow icmp destination unreachable messages"},
-				{"icmp", "--icmp-type", "time-exceeded", "allow icmp time exceeded messages"},
+				{"ipv6-icmp", "--icmpv6-type", "echo-request", "allow icmp echo requests"},
+				{"ipv6-icmp", "--icmpv6-type", "destination-unreachable", "allow icmp destination unreachable messages"},
+				{"ipv6-icmp", "--icmpv6-type", "time-exceeded", "allow icmp time exceeded messages"},
 				{"ipv6-icmp", "--icmpv6-type", "neighbor-solicitation", "allow icmp neighbor solicitation messages"},
 				{"ipv6-icmp", "--icmpv6-type", "neighbor-advertisement", "allow icmp neighbor advertisement messages"},
 				{"ipv6-icmp", "--icmpv6-type", "echo-reply", "allow icmp echo reply messages"},
Repository: cloudnativelabs/kube-router
Pull request #1714 (2024-08-09 08:52:27)

Prep v2.2.1


Patch:
diff --git a/pkg/utils/iptables.go b/pkg/utils/iptables.go
index 45cecdda..f1a5bc26 100644
--- a/pkg/utils/iptables.go
+++ b/pkg/utils/iptables.go
@@ -200,12 +200,22 @@ func (i *IPTablesSaveRestore) Restore(table string, data []byte) error {
 func CommonICMPRules(family v1core.IPFamily) []ICMPRule {
 	// Allow various types of ICMP that are important for routing
 	// This first block applies to both IPv4 and IPv6 type rules
+
+	var icmpProto, icmpType string
+	if family == v1core.IPv6Protocol {
+		icmpProto = ICMPv6Proto
+		icmpType = ICMPv6Type
+	} else {
+		icmpProto = ICMPv4Proto
+		icmpType = ICMPv4Type
+	}
+
 	icmpRules := []ICMPRule{
-		{ICMPv4Proto, ICMPv4Type, "echo-request", "allow icmp echo requests"},
+		{icmpProto, icmpType, "echo-request", "allow icmp echo requests"},
 		// destination-unreachable here is also responsible for handling / allowing PMTU
 		// (https://en.wikipedia.org/wiki/Path_MTU_Discovery) responses
-		{ICMPv4Proto, ICMPv4Type, "destination-unreachable", "allow icmp destination unreachable messages"},
-		{ICMPv4Proto, ICMPv4Type, "time-exceeded", "allow icmp time exceeded messages"},
+		{icmpProto, icmpType, "destination-unreachable", "allow icmp destination unreachable messages"},
+		{icmpProto, icmpType, "time-exceeded", "allow icmp time exceeded messages"},
 	}
 
 	if family == v1core.IPv6Protocol {


Test patch:
diff --git a/pkg/utils/iptables_test.go b/pkg/utils/iptables_test.go
index 96e55403..90ac6ba3 100644
--- a/pkg/utils/iptables_test.go
+++ b/pkg/utils/iptables_test.go
@@ -27,9 +27,9 @@ func TestCommonICMPRules(t *testing.T) {
 			name:   "IPv6",
 			family: v1core.IPv6Protocol,
 			expected: []ICMPRule{
-				{"icmp", "--icmp-type", "echo-request", "allow icmp echo requests"},
-				{"icmp", "--icmp-type", "destination-unreachable", "allow icmp destination unreachable messages"},
-				{"icmp", "--icmp-type", "time-exceeded", "allow icmp time exceeded messages"},
+				{"ipv6-icmp", "--icmpv6-type", "echo-request", "allow icmp echo requests"},
+				{"ipv6-icmp", "--icmpv6-type", "destination-unreachable", "allow icmp destination unreachable messages"},
+				{"ipv6-icmp", "--icmpv6-type", "time-exceeded", "allow icmp time exceeded messages"},
 				{"ipv6-icmp", "--icmpv6-type", "neighbor-solicitation", "allow icmp neighbor solicitation messages"},
 				{"ipv6-icmp", "--icmpv6-type", "neighbor-advertisement", "allow icmp neighbor advertisement messages"},
 				{"ipv6-icmp", "--icmpv6-type", "echo-reply", "allow icmp echo reply messages"},
Repository: trinodb/trino-python-client
Pull request #97 (2021-08-17 08:35:59)

Add type annotations and tests for transaction isolation level


Patch:
diff --git a/trino/transaction.py b/trino/transaction.py
index ce85652..b6f3b2f 100644
--- a/trino/transaction.py
+++ b/trino/transaction.py
@@ -9,6 +9,7 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
+from typing import Iterable
 
 from trino import constants
 import trino.client
@@ -33,15 +34,15 @@ class IsolationLevel(object):
     SERIALIZABLE = 4
 
     @classmethod
-    def levels(cls):
-        return {k for k in cls.__dict__.keys() if not k.startswith("_")}
+    def levels(cls) -> Iterable[str]:
+        return {k for k, v in cls.__dict__.items() if not k.startswith("_") and isinstance(v, int)}
 
     @classmethod
-    def values(cls):
+    def values(cls) -> Iterable[int]:
         return {getattr(cls, level) for level in cls.levels()}
 
     @classmethod
-    def check(cls, level):
+    def check(cls, level: int) -> int:
         if level not in cls.values():
             raise ValueError("invalid isolation level {}".format(level))
         return level


Test patch:
diff --git a/tests/test_transaction.py b/tests/test_transaction.py
new file mode 100644
index 0000000..e97903c
--- /dev/null
+++ b/tests/test_transaction.py
@@ -0,0 +1,43 @@
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from trino.transaction import IsolationLevel
+import pytest
+
+
+def test_isolation_level_levels() -> None:
+    levels = {
+        "AUTOCOMMIT",
+        "READ_UNCOMMITTED",
+        "READ_COMMITTED",
+        "REPEATABLE_READ",
+        "SERIALIZABLE",
+    }
+
+    assert IsolationLevel.levels() == levels
+
+
+def test_isolation_level_values() -> None:
+    values = {
+        0, 1, 2, 3, 4
+    }
+
+    assert IsolationLevel.values() == values
+
+
+def test_isolation_level_check_match() -> None:
+    assert IsolationLevel.check(3) == 3
+
+
+def test_isolation_level_check_mismatch() -> None:
+    with pytest.raises(ValueError):
+        IsolationLevel.check(-1)
Repository: trinodb/trino-python-client
Pull request #420 (2023-10-18 02:07:37)

Check cursor _query is None before columns
<!-- Thank you for submitting a pull request! Find more information in our development guide at https://github.com/trinodb/trino/blob/master/.github/DEVELOPMENT.md and contact us on #python-client in Slack. -->
<!-- Provide an overview of the PR for maintainers and reviewers. -->
## Description
Fixes an issue where if `cursor.description` is called before `execute`, then it returns `AttributeError` for `columns`. This make this client not work with [Ray Data](https://github.com/ray-project/ray/blob/master/python/ray/data/datasource/sql_datasource.py#L71-L81) because it checks if `description` exists.


<!-- Provide a user-friendly explanation, keep it brief if it isn't user-visible. -->
## Non-technical explanation
Guard against error state when calling a function


<!-- Mark the appropriate option with an (x). Propose a release note if you can. -->
## Release notes

(x) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text:


cla-bot[bot]: Thank you for your pull request and welcome to the Trino community. We require contributors to sign our [Contributor License Agreement](https://github.com/trinodb/cla/raw/master/Trino%20Foundation%20Individual%20CLA.pdf), and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to cla@trino.io. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla
hashhar: @cla-bot check
hashhar: @ammarar Can you fix flake8 failure?

Please amend the commit and force push instead of adding a new commit.
I'll merge after CI is done.
ammarar: @hashhar It's done! Its all yours now.

Patch:
diff --git a/trino/dbapi.py b/trino/dbapi.py
index a417f52..c660772 100644
--- a/trino/dbapi.py
+++ b/trino/dbapi.py
@@ -376,7 +376,7 @@ class Cursor(object):
 
     @property
     def description(self) -> List[ColumnDescription]:
-        if self._query.columns is None:
+        if self._query is None or self._query.columns is None:
             return None
 
         # [ (name, type_code, display_size, internal_size, precision, scale, null_ok) ]


Test patch:
diff --git a/tests/unit/test_dbapi.py b/tests/unit/test_dbapi.py
index b56466a..e285723 100644
--- a/tests/unit/test_dbapi.py
+++ b/tests/unit/test_dbapi.py
@@ -309,3 +309,9 @@ def test_hostname_parsing():
     assert only_hostname_with_path.host == "mytrinoserver.domain/some_path"
     assert only_hostname_with_path.port == 8080
     assert only_hostname_with_path.http_scheme == constants.HTTP
+
+
+def test_description_is_none_when_cursor_is_not_executed():
+    connection = Connection("sample_trino_cluster:443")
+    cursor = connection.cursor()
+    assert hasattr(cursor, 'description')