different behaviour in GET vs POST when trailing space in platform name #3962

Closed
opened 2025-12-29 18:32:19 +01:00 by adam · 1 comment
Owner

Originally created by @gstorme on GitHub (Aug 9, 2020).

Environment

  • Python version: 3.7.3
  • NetBox version: 2.8.9

Steps to Reproduce

  1. POST /api/dcim/platforms/ with data:
{
  "name": "Linux 4.18.0-147.8.1.el8_1.x86_64 CentOS Linux release 8.1.1911 (Core) ",
  "slug": "linux-4-18-0-147-8-1-el8_1-x86_64-centos-linux-release-8-1-1911-core-"
}
  1. GET /api/dcim/platforms/?name=Linux%204.18.0-147.8.1.el8_1.x86_64%20CentOS%20Linux%20release%208.1.1911%20(Core)
  2. GET /api/dcim/platforms/?name=Linux%204.18.0-147.8.1.el8_1.x86_64%20CentOS%20Linux%20release%208.1.1911%20(Core)%20

Expected Behavior

Both GET requests return the same response, with or without the trailing space in the platform name.
Because a POST request strips the trailing space.

Observed Behavior

The POST request creates the platform, and strips the trailing space from the name:

{
  "id": 54,
  "name": "Linux 4.18.0-147.8.1.el8_1.x86_64 CentOS Linux release 8.1.1911 (Core)",
  "slug": "linux-4-18-0-147-8-1-el8_1-x86_64-centos-linux-release-8-1-1911-core-",
}

The GET request without a trailing space returns count 1
The GET request with a trailing space returns count 0
The POST is hit again because the GET count was 0, and returns a "400 Bad Request":

{
  "name": [
    "platform with this name already exists."
  ],
  "slug": [
    "platform with this slug already exists."
  ]
}
Originally created by @gstorme on GitHub (Aug 9, 2020). ### Environment * Python version: 3.7.3 * NetBox version: 2.8.9 <!-- Describe in detail the exact steps that someone else can take to reproduce this bug using the current stable release of NetBox. Begin with the creation of any necessary database objects and call out every operation being performed explicitly. If reporting a bug in the REST API, be sure to reconstruct the raw HTTP request(s) being made: Don't rely on a client library such as pynetbox. --> ### Steps to Reproduce 1. POST `/api/dcim/platforms/` with data: ``` { "name": "Linux 4.18.0-147.8.1.el8_1.x86_64 CentOS Linux release 8.1.1911 (Core) ", "slug": "linux-4-18-0-147-8-1-el8_1-x86_64-centos-linux-release-8-1-1911-core-" } ``` 2. GET `/api/dcim/platforms/?name=Linux%204.18.0-147.8.1.el8_1.x86_64%20CentOS%20Linux%20release%208.1.1911%20(Core)` 3. GET `/api/dcim/platforms/?name=Linux%204.18.0-147.8.1.el8_1.x86_64%20CentOS%20Linux%20release%208.1.1911%20(Core)%20` <!-- What did you expect to happen? --> ### Expected Behavior Both GET requests return the same response, with or without the trailing space in the platform name. Because a POST request strips the trailing space. <!-- What happened instead? --> ### Observed Behavior The POST request creates the platform, and strips the trailing space from the name: ``` { "id": 54, "name": "Linux 4.18.0-147.8.1.el8_1.x86_64 CentOS Linux release 8.1.1911 (Core)", "slug": "linux-4-18-0-147-8-1-el8_1-x86_64-centos-linux-release-8-1-1911-core-", } ``` The GET request without a trailing space returns count 1 The GET request with a trailing space returns count 0 The POST is hit again because the GET count was 0, and returns a "400 Bad Request": ``` { "name": [ "platform with this name already exists." ], "slug": [ "platform with this slug already exists." ] } ```
adam closed this issue 2025-12-29 18:32:19 +01:00
Author
Owner

@lampwins commented on GitHub (Aug 10, 2020):

This is expected behavior per upstream functionality in Django REST Framework (see https://github.com/encode/django-rest-framework/issues/2517). The platform object is being created without a trailing space and thus your GET request with a space correctly returns no results because a platform object with a space does not exist. When you try to create another via POST, the space is stripped again and thus the request fails because a platform with the resulting name already exists.

@lampwins commented on GitHub (Aug 10, 2020): This is expected behavior per upstream functionality in Django REST Framework (see https://github.com/encode/django-rest-framework/issues/2517). The platform object is being created without a trailing space and thus your GET request with a space correctly returns no results because a platform object with a space does not exist. When you try to create another via POST, the space is stripped again and thus the request fails because a platform with the resulting name already exists.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#3962