You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by dy...@apache.org on 2018/08/29 16:13:24 UTC
[trafficcontrol] 02/02: Fixes #2397 - Change nil to empty string in
parameter endpoint before create update
This is an automated email from the ASF dual-hosted git repository.
dylan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
commit 1f29507876bd9540a27685bedbe8cd8a257cfa7f
Author: cgillo000 <ch...@cable.comcast.com>
AuthorDate: Thu Aug 23 11:30:15 2018 -0600
Fixes #2397 - Change nil to empty string in parameter endpoint before create update
---
...1_remove_parameter_value_nonnull_constraint.sql | 26 ----------------------
.../traffic_ops_golang/parameter/parameters.go | 10 ++++++++-
2 files changed, 9 insertions(+), 27 deletions(-)
diff --git a/traffic_ops/app/db/migrations/20180815000811_remove_parameter_value_nonnull_constraint.sql b/traffic_ops/app/db/migrations/20180815000811_remove_parameter_value_nonnull_constraint.sql
deleted file mode 100644
index 3fb3e8e..0000000
--- a/traffic_ops/app/db/migrations/20180815000811_remove_parameter_value_nonnull_constraint.sql
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
-
- 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.
-*/
-
--- +goose Up
--- SQL in section 'Up' is executed when this migration is applied
-
-ALTER TABLE parameter
-ALTER value DROP NOT NULL;
-
--- +goose Down
--- SQL section 'Down' is executed when this migration is rolled back
-
-ALTER TABLE parameter
-ALTER value SET NOT NULL;
diff --git a/traffic_ops/traffic_ops_golang/parameter/parameters.go b/traffic_ops/traffic_ops_golang/parameter/parameters.go
index c7708eb..4c5d652 100644
--- a/traffic_ops/traffic_ops_golang/parameter/parameters.go
+++ b/traffic_ops/traffic_ops_golang/parameter/parameters.go
@@ -99,7 +99,7 @@ func (param TOParameter) Validate() error {
// - Secure Flag is always set to either 1/0
// - Admin rights only
// - Do not allow duplicate parameters by name+config_file+value
- // - Removed NOT NULL constraint on 'value' so removed it's validation as .Required
+ // - Client can send NOT NULL constraint on 'value' so removed it's validation as .Required
errs := validation.Errors{
NameQueryParam: validation.Validate(param.Name, validation.Required),
ConfigFileQueryParam: validation.Validate(param.ConfigFile, validation.Required),
@@ -116,6 +116,10 @@ func (param TOParameter) Validate() error {
//The insert sql returns the id and lastUpdated values of the newly inserted parameter and have
//to be added to the struct
func (param *TOParameter) Create() (error, tc.ApiErrorType) {
+ if param.Value == nil {
+ val := ""
+ param.Value = &val
+ }
resultRows, err := param.ReqInfo.Tx.NamedQuery(insertQuery(), param)
if err != nil {
if pqErr, ok := err.(*pq.Error); ok {
@@ -227,6 +231,10 @@ func (param *TOParameter) Read(parameters map[string]string) ([]interface{}, []e
//if so, it will return an errorType of DataConflict and the type should be appended to the
//generic error message returned
func (param *TOParameter) Update() (error, tc.ApiErrorType) {
+ if param.Value == nil {
+ val := ""
+ param.Value = &val
+ }
log.Debugf("about to run exec query: %s with parameter: %++v", updateQuery(), param)
resultRows, err := param.ReqInfo.Tx.NamedQuery(updateQuery(), param)
if err != nil {