diff --git a/modules/pubmatic/openwrap/database/mysql/adunit_config.go b/modules/pubmatic/openwrap/database/mysql/adunit_config.go index 204cf02327b..6f5fce46c0f 100644 --- a/modules/pubmatic/openwrap/database/mysql/adunit_config.go +++ b/modules/pubmatic/openwrap/database/mysql/adunit_config.go @@ -1,6 +1,7 @@ package mysql import ( + "database/sql" "encoding/json" "strconv" "strings" @@ -21,6 +22,9 @@ func (db *mySqlDB) GetAdunitConfig(profileID, displayVersion int) (*adunitconfig var adunitConfigJSON string err := db.conn.QueryRow(adunitConfigQuery).Scan(&adunitConfigJSON) if err != nil { + if err == sql.ErrNoRows { + return nil, nil + } return nil, err } diff --git a/modules/pubmatic/openwrap/database/mysql/adunit_config_test.go b/modules/pubmatic/openwrap/database/mysql/adunit_config_test.go index 57faca742af..0bd64c1530c 100644 --- a/modules/pubmatic/openwrap/database/mysql/adunit_config_test.go +++ b/modules/pubmatic/openwrap/database/mysql/adunit_config_test.go @@ -40,6 +40,31 @@ func Test_mySqlDB_GetAdunitConfig(t *testing.T) { return db }, }, + { + name: "adunitconfig not found for profile(No rows error)", + fields: fields{ + cfg: config.Database{ + Queries: config.Queries{ + GetAdunitConfigForLiveVersion: "^SELECT (.+) FROM wrapper_media_config (.+) LIVE", + }, + }, + }, + args: args{ + profileID: 5890, + displayVersion: 0, + }, + want: nil, + wantErr: false, + setup: func() *sql.DB { + db, mock, err := sqlmock.New() + if err != nil { + t.Fatalf("an error '%s' was not expected when opening a stub database connection", err) + } + rows := sqlmock.NewRows([]string{}) + mock.ExpectQuery(regexp.QuoteMeta("^SELECT (.+) FROM wrapper_media_config (.+) LIVE")).WillReturnRows(rows) + return db + }, + }, { name: "query with display version id 0", fields: fields{