This is an automated email from the ASF dual-hosted git repository.

shamrick pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 2257ddb1a4 Fixed ASN Update logic for APIv5 (#7767)
2257ddb1a4 is described below

commit 2257ddb1a49c0b157206a92e753a01ce46eab165
Author: Rima Shah <[email protected]>
AuthorDate: Thu Aug 31 10:53:07 2023 -0600

    Fixed ASN Update logic for APIv5 (#7767)
    
    * fixing the logic for asn-update for v5
    
    * update changelog
---
 CHANGELOG.md                               | 1 +
 traffic_ops/traffic_ops_golang/asn/asns.go | 8 ++++----
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index b8670e95ba..728dc46ad4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -79,6 +79,7 @@ The format is based on [Keep a 
Changelog](http://keepachangelog.com/en/1.0.0/).
 - [#7765](https://github.com/apache/trafficcontrol/pull/7765) *Traffic Stats* 
now uses Traffic Ops APIv5
 
 ### Fixed
+- [#7767](https://github.com/apache/trafficcontrol/pull/7767) *Traffic Ops* 
Fixed ASN update logic for APIv5
 - [RFC3339](https://github.com/apache/trafficcontrol/issues/5911)
     - [#7759](https://github.com/apache/trafficcontrol/pull/7759) *Traffic 
Ops* Fixed `/profiles/{{ID}}/parameters` and 
`profiles/name/{{name}}/parameters` v5 APIs to respond with `RFC3339` 
timestamps.
     - [#7734](https://github.com/apache/trafficcontrol/pull/7734) *Traffic 
Ops* Fixed `/profiles` v5 APIs to respond with `RFC3339` timestamps.
diff --git a/traffic_ops/traffic_ops_golang/asn/asns.go 
b/traffic_ops/traffic_ops_golang/asn/asns.go
index 5954594f87..d0aa231c8b 100644
--- a/traffic_ops/traffic_ops_golang/asn/asns.go
+++ b/traffic_ops/traffic_ops_golang/asn/asns.go
@@ -341,13 +341,13 @@ func Update(w http.ResponseWriter, r *http.Request) {
        }
 
        // check if asn already exists
-       var count int
-       err := tx.QueryRow("SELECT count(*) from asn where asn=$1", 
asn.ASN).Scan(&count)
-       if err != nil {
+       var id int
+       err := tx.QueryRow("SELECT id from asn where asn=$1", asn.ASN).Scan(&id)
+       if err != nil && err != sql.ErrNoRows {
                api.HandleErr(w, r, tx, http.StatusInternalServerError, nil, 
fmt.Errorf("error: %w, when checking if asn '%d' exists", err, asn.ASN))
                return
        }
-       if count == 1 {
+       if id != 0 && id != requestedAsnId {
                api.HandleErr(w, r, tx, http.StatusBadRequest, 
fmt.Errorf("asn:'%d' already exists", asn.ASN), nil)
                return
        }

Reply via email to