nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: ariga/atlas
Pull request #2549 (2024-02-17 09:09:05)

sql/sqlx: drop the table before drop UDTs
When table's triggers referenced to other types, it should drop first then types.



Patch:
diff --git a/sql/internal/sqlx/plan.go b/sql/internal/sqlx/plan.go
index bc1c346b..619406cd 100644
--- a/sql/internal/sqlx/plan.go
+++ b/sql/internal/sqlx/plan.go
@@ -660,10 +660,27 @@ func dependsOn(c1, c2 schema.Change) bool {
 		}
 		// Dropping a type must occur after all its usage were dropped.
 		switch c2 := c2.(type) {
+		case *schema.DropView:
+			// Dropping a view also drops its triggers
+			// and they might depend on the type.
+			if slices.ContainsFunc(c2.V.Triggers, func(tg *schema.Trigger) bool {
+				return slices.Contains(tg.Deps, c1.O)
+			}) {
+				return true
+			}
 		case *schema.DropTable:
-			return slices.ContainsFunc(c2.T.Columns, func(c *schema.Column) bool {
+			// Dropping a table also drops its triggers
+			// and they might depend on the type.
+			if slices.ContainsFunc(c2.T.Triggers, func(tg *schema.Trigger) bool {
+				return slices.Contains(tg.Deps, c1.O)
+			}) {
+				return true
+			}
+			if slices.ContainsFunc(c2.T.Columns, func(c *schema.Column) bool {
 				return dependsOnT(c.Type.Type, t)
-			})
+			}) {
+				return true
+			}
 		case *schema.ModifyTable:
 			return slices.ContainsFunc(c2.Changes, func(c schema.Change) bool {
 				d, ok := c.(*schema.DropColumn)


Test patch:
diff --git a/sql/internal/sqlx/plan_test.go b/sql/internal/sqlx/plan_test.go
index 571c2894..90ab3849 100644
--- a/sql/internal/sqlx/plan_test.go
+++ b/sql/internal/sqlx/plan_test.go
@@ -177,7 +177,9 @@ func TestSortChanges(t *testing.T) {
 	}
 	t1.AddForeignKeys(schema.NewForeignKey("t1").AddColumns(t1.Columns[1:2]...).SetRefTable(t1).AddRefColumns(t1.Columns[:1]...))
 	f1 := &schema.Func{Name: "f1", Deps: []schema.Object{t1}}
+	e1 := &schema.EnumType{T: "e1", Values: []string{"v1", "v2"}}
 	tr1 := &schema.Trigger{Name: "tr", Table: t1, Deps: []schema.Object{f1}}
+	tr2 := &schema.Trigger{Name: "tr2", Table: t1, Deps: []schema.Object{e1}}
 	changes := []schema.Change{
 		&schema.ModifyTable{T: t1},
 		&schema.AddTrigger{T: tr1},
@@ -202,6 +204,15 @@ func TestSortChanges(t *testing.T) {
 	})
 	require.Equal(t, []schema.Change{&schema.DropFunc{F: f1}, &schema.DropTable{T: t1}}, planned)
 
+	// The table must be dropped before the enum type if one of its triggers depends on the enum type.
+	t1.Triggers = []*schema.Trigger{tr2}
+	changes = []schema.Change{
+		&schema.DropObject{O: e1},
+		&schema.DropTable{T: t1},
+	}
+	planned = SortChanges(changes)
+	require.Equal(t, []schema.Change{changes[1], changes[0]}, planned)
+
 	// The table must be dropped before the function if one of its triggers depends on the function.
 	t1.Triggers = []*schema.Trigger{tr1}
 	planned = SortChanges([]schema.Change{
Repository: ariga/atlas
Pull request #2555 (2024-02-19 15:35:36)

sql/sqlcheck: fix suggestion for dropping column


Patch:
diff --git a/sql/sqlcheck/destructive/destructive.go b/sql/sqlcheck/destructive/destructive.go
index 653be0f0..ec7eb8b8 100644
--- a/sql/sqlcheck/destructive/destructive.go
+++ b/sql/sqlcheck/destructive/destructive.go
@@ -111,7 +111,7 @@ func (a *Analyzer) Analyze(_ context.Context, p *sqlcheck.Pass) error {
 						Text: fmt.Sprintf("Dropping non-virtual column %s", names[0]),
 						SuggestedFixes: []sqlcheck.SuggestedFix{
 							{
-								Message: fmt.Sprintf("Add a pre-migration check to ensure column %q is NULL before dropping it", c.T.Name),
+								Message: fmt.Sprintf("Add a pre-migration check to ensure column %s is NULL before dropping it", names[0]),
 							},
 						},
 					})


Test patch:
diff --git a/sql/sqlcheck/destructive/destructive_test.go b/sql/sqlcheck/destructive/destructive_test.go
index 063a27b3..6902aeae 100644
--- a/sql/sqlcheck/destructive/destructive_test.go
+++ b/sql/sqlcheck/destructive/destructive_test.go
@@ -245,6 +245,8 @@ func TestAnalyzer_DropColumn(t *testing.T) {
 	require.Len(t, report.Diagnostics, 1)
 	require.Equal(t, "destructive changes detected", report.Text)
 	require.Equal(t, `Dropping non-virtual column "c"`, report.Diagnostics[0].Text)
+	require.Len(t, report.Diagnostics[0].SuggestedFixes, 1)
+	require.Equal(t, "Add a pre-migration check to ensure column \"c\" is NULL before dropping it", report.Diagnostics[0].SuggestedFixes[0].Message)
 }
 
 type testFile struct {
Repository: ariga/atlas
Pull request #2576 (2024-02-25 15:05:00)

sql/sqlx: respect type in deps list of func/proc
- sql/sqlx: respect type in deps list of func/proc
- sql/specutil: sort `depends_on` by used its name


Patch:
diff --git a/sql/internal/specutil/convert.go b/sql/internal/specutil/convert.go
index 59e82efc..a38f2313 100644
--- a/sql/internal/specutil/convert.go
+++ b/sql/internal/specutil/convert.go
@@ -7,6 +7,7 @@ package specutil
 import (
 	"errors"
 	"fmt"
+	"slices"
 	"strconv"
 	"strings"
 
@@ -756,6 +757,9 @@ func dependsOn(realm *schema.Realm, objects []schema.Object) (*schemahcl.Attr, b
 		}))
 	}
 	if len(deps) > 0 {
+		slices.SortFunc(deps, func(l, r *schemahcl.Ref) int {
+			return strings.Compare(l.V, r.V)
+		})
 		return schemahcl.RefsAttr("depends_on", deps...), true
 	}
 	return nil, false
diff --git a/sql/internal/sqlx/plan.go b/sql/internal/sqlx/plan.go
index 9bcc15ee..14f902db 100644
--- a/sql/internal/sqlx/plan.go
+++ b/sql/internal/sqlx/plan.go
@@ -578,6 +578,13 @@ func dependsOn(c1, c2 schema.Change) bool {
 			if funcDep(c1.F, c2.To) {
 				return true // Relies on the new definition.
 			}
+		case *schema.AddObject:
+			t, ok := c2.O.(schema.Type)
+			if ok && (c1.F.Ret == t || slices.ContainsFunc(c1.F.Args, func(f *schema.FuncArg) bool {
+				return dependsOnT(f.Type, t)
+			})) {
+				return true
+			}
 		}
 		return depOfAdd(c1.F.Deps, c2)
 	case *schema.DropFunc:
@@ -623,6 +630,13 @@ func dependsOn(c1, c2 schema.Change) bool {
 			if procDep(c1.P, c2.To) {
 				return true // Relies on the new definition.
 			}
+		case *schema.AddObject:
+			t, ok := c2.O.(schema.Type)
+			if ok && slices.ContainsFunc(c1.P.Args, func(f *schema.FuncArg) bool {
+				return dependsOnT(f.Type, t)
+			}) {
+				return true
+			}
 		}
 	case *schema.DropProc:
 		switch c2 := c2.(type) {
@@ -687,11 +701,11 @@ func dependsOn(c1, c2 schema.Change) bool {
 				return ok && dependsOnT(d.C.Type.Type, t)
 			})
 		case *schema.DropFunc:
-			return c2.F.Ret == t || slices.ContainsFunc(c2.F.Args, func(f *schema.FuncArg) bool {
+			return slices.Contains(c2.F.Deps, c1.O) || c2.F.Ret == t || slices.ContainsFunc(c2.F.Args, func(f *schema.FuncArg) bool {
 				return dependsOnT(f.Type, t)
 			})
 		case *schema.DropProc:
-			return slices.ContainsFunc(c2.P.Args, func(f *schema.FuncArg) bool {
+			return slices.Contains(c2.P.Deps, c1.O) || slices.ContainsFunc(c2.P.Args, func(f *schema.FuncArg) bool {
 				return dependsOnT(f.Type, t)
 			})
 		}


Test patch:
diff --git a/sql/postgres/sqlspec_test.go b/sql/postgres/sqlspec_test.go
index e96c634b..99ff6929 100644
--- a/sql/postgres/sqlspec_test.go
+++ b/sql/postgres/sqlspec_test.go
@@ -372,7 +372,7 @@ view "v3" {
 view "v4" {
   schema     = schema.public
   as         = "SELECT * FROM v2 JOIN t1 USING (id)"
-  depends_on = [view.v2, table.t1]
+  depends_on = [table.t1, view.v2]
 }
 materialized "m1" {
   schema = schema.public
@@ -381,7 +381,7 @@ materialized "m1" {
 materialized "m2" {
   schema     = schema.public
   as         = "SELECT * FROM t1"
-  depends_on = [view.v2, materialized.m1, table.t1]
+  depends_on = [materialized.m1, table.t1, view.v2]
 }
 schema "public" {
 }
Repository: box/box-python-sdk
Pull request #51 (2015-05-28 20:23:54)

Return bool from `Item.remove_shared_link()`.
Make the return type match the type specified in the docstring.  The
method was previously attempting to return ``unicode or None``.

The method was also previously attempting to access the 'url' item on
the shared_link object. However, the Box API returns a null object when
the shared link is disabled [1]. Make the method check for success by
doing an ``is None`` check on the shared_link object.

[1] https://box-content.readme.io/#create-a-shared-link-for-a-folder


Patch:
diff --git a/boxsdk/object/item.py b/boxsdk/object/item.py
index e507e86..5edfd82 100644
--- a/boxsdk/object/item.py
+++ b/boxsdk/object/item.py
@@ -200,7 +200,7 @@ def remove_shared_link(self, etag=None):
         """
         data = {'shared_link': None}
         item = self.update_info(data, etag=etag)
-        return item.shared_link['url']
+        return item.shared_link is None
 
     def delete(self, params=None, etag=None):
         """Delete the item.


Test patch:
diff --git a/test/unit/object/test_item.py b/test/unit/object/test_item.py
index 1bfa2f1..8cc481a 100644
--- a/test/unit/object/test_item.py
+++ b/test/unit/object/test_item.py
@@ -83,15 +83,15 @@ def test_remove_shared_link(test_item_and_response, mock_box_session, etag, if_m
     # pylint:disable=redefined-outer-name, protected-access
     test_item, _ = test_item_and_response
     expected_url = test_item.get_url()
-    mock_box_session.put.return_value.json.return_value = {'shared_link': {'url': None}}
-    url = test_item.remove_shared_link(etag=etag)
+    mock_box_session.put.return_value.json.return_value = {'shared_link': None}
+    removed = test_item.remove_shared_link(etag=etag)
     mock_box_session.put.assert_called_once_with(
         expected_url,
         data=json.dumps({'shared_link': None}),
         headers=if_match_header,
         params=None,
     )
-    assert url is None
+    assert removed is True
 
 
 @pytest.mark.parametrize('fields', (None, ['name', 'created_at']))
Repository: box/box-python-sdk
Pull request #290 (2018-06-26 20:24:05)

Add type check in logging sanitizer
Log sanitization should not attempt to sanitize non-string values,
since they are not guaranteed to be subscriptable.

jmoldow: We can add a unit test for this.

Patch:
diff --git a/boxsdk/util/log.py b/boxsdk/util/log.py
index 7a90774..f0eb538 100644
--- a/boxsdk/util/log.py
+++ b/boxsdk/util/log.py
@@ -59,7 +59,7 @@ def sanitize_dictionary(self, dictionary):
             return dictionary
         sanitized_dictionary = {}
         for key, value in iteritems(dictionary):
-            if key in self.KEYS_TO_SANITIZE:
+            if key in self.KEYS_TO_SANITIZE and isinstance(value, string_types):
                 sanitized_dictionary[key] = self.sanitize_value(value)
             elif isinstance(value, Mapping):
                 sanitized_dictionary[key] = self.sanitize_dictionary(value)


Test patch:
diff --git a/test/unit/util/test_log.py b/test/unit/util/test_log.py
index 0d1211e..4bd861b 100644
--- a/test/unit/util/test_log.py
+++ b/test/unit/util/test_log.py
@@ -77,3 +77,43 @@ def test_setup_logging_is_reentrant(mock_logger):
 
     if isinstance(stream_or_file, string_types):
         assert mock_file_open.call_count == 1
+
+
+@pytest.mark.parametrize(
+    'unsanitized_dict, expected_result',
+    [
+        # Test for when no sanitization is required
+        (
+            {'name': 'foo'},
+            {'name': 'foo'},
+        ),
+        # Test for basic string sanitization
+        (
+            {'access_token': 'askdjfhadsrwedr'},
+            {'access_token': '---wedr'},
+        ),
+        # Test for short string sanitization
+        (
+            {'refresh_token': 'abc'},
+            {'refresh_token': '---abc'},
+        ),
+        # Test for recursive sanitization
+        (
+            {'stuff': {'shared_link': 'https://example.com/asdfghjkl'}},
+            {'stuff': {'shared_link': '---hjkl'}},
+        ),
+        # Test for None type
+        (
+            {'download_url': None},
+            {'download_url': None},
+        ),
+    ]
+)
+def test_sanitize_dictionary_correctly_sanitizes_params(mock_logger, unsanitized_dict, expected_result):
+    mock_file_open = mock_open()
+
+    with patch('logging.getLogger') as get_logger:
+        with patch('logging.open', mock_file_open, create=True):
+            get_logger.return_value = mock_logger
+            actual_result = boxsdk.util.log.Logging().sanitize_dictionary(unsanitized_dict)
+            assert actual_result == expected_result
Repository: sashabaranov/go-openai
Pull request #123 (2023-03-04 22:19:12)

add "name" property for ChatCompletionMessage
I found an undocumented possibility - for messages of the gpt-3.5 model, you can additionally specify the "name" property. This additional feature is useful for chats with multiple participants.

Found in the examples of the official library for python (Item No. 6 - Counting tokens for chat API calls): [https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken .ipynb](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb)

sashabaranov: Nice find! Thank you for the PR 🙌

Could you please add a comment in code about that field being non-documented in the official docs?
fussraider: Yes, no problem. Added 👌

Patch:
diff --git a/audio.go b/audio.go
index 1ba8438..54bd32f 100644
--- a/audio.go
+++ b/audio.go
@@ -35,7 +35,7 @@ func (c *Client) CreateTranscription(
 	return
 }
 
-// CreateTranscription — API call to create a transcription. Returns transcribed text.
+// CreateTranslation — API call to translate audio into English.
 func (c *Client) CreateTranslation(
 	ctx context.Context,
 	request AudioRequest,
diff --git a/chat.go b/chat.go
index 8f49769..cfa86b6 100644
--- a/chat.go
+++ b/chat.go
@@ -22,6 +22,12 @@ var (
 type ChatCompletionMessage struct {
 	Role    string `json:"role"`
 	Content string `json:"content"`
+
+	// This property isn't in the official documentation, but it's in
+	// the documentation for the official library for python:
+	// - https://github.com/openai/openai-python/blob/main/chatml.md
+	// - https://github.com/openai/openai-cookbook/blob/main/examples/How_to_count_tokens_with_tiktoken.ipynb
+	Name string `json:"name,omitempty"`
 }
 
 // ChatCompletionRequest represents a request structure for chat completion API.


Test patch:
diff --git a/api_test.go b/api_test.go
index cb473fb..e8257db 100644
--- a/api_test.go
+++ b/api_test.go
@@ -59,7 +59,7 @@ func TestAPI(t *testing.T) {
 			Model: GPT3Dot5Turbo,
 			Messages: []ChatCompletionMessage{
 				{
-					Role:    "user",
+					Role:    ChatMessageRoleUser,
 					Content: "Hello!",
 				},
 			},
@@ -67,7 +67,25 @@ func TestAPI(t *testing.T) {
 	)
 
 	if err != nil {
-		t.Errorf("CreateChatCompletion returned error: %v", err)
+		t.Errorf("CreateChatCompletion (without name) returned error: %v", err)
+	}
+
+	_, err = c.CreateChatCompletion(
+		ctx,
+		ChatCompletionRequest{
+			Model: GPT3Dot5Turbo,
+			Messages: []ChatCompletionMessage{
+				{
+					Role:    ChatMessageRoleUser,
+					Name:    "John_Doe",
+					Content: "Hello!",
+				},
+			},
+		},
+	)
+
+	if err != nil {
+		t.Errorf("CreateChatCompletion (with name) returned error: %v", err)
 	}
 
 	stream, err := c.CreateCompletionStream(ctx, CompletionRequest{