String attributes should limit the length in API

Bug #1193253 reported by yong sheng gong
30
This bug affects 5 people
Affects Status Importance Assigned to Milestone
neutron
Fix Released
Medium
Mark McClain

Bug Description

I use the latest code of Grizzly, and create a network. The name of network is longer then 255 characters.
Then I list networks, the name of network has only 255 characters.
This is my request:
{
  "network":
  {
    "name": "test12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"
  }
}

And this is list network responce:
{
    "networks": [
        {
            "status": "ACTIVE",
            "subnets": [],
            "name": "test12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901",
            "provider:physical_network": "physnet1",
            "admin_state_up": true,
            "tenant_id": "6fbe9263116a4b68818cf1edce16bc4f",
            "provider:network_type": "vlan",
            "router:external": false,
            "shared": false,
            "id": "40a59f54-d8c0-432c-a2ef-6a8151348054",
            "provider:segmentation_id": 54
        }
    ]
}

The name lost 9 characters.

I found the code in /quantum/db/models_v2.py

class Network(model_base.BASEV2, HasId, HasTenant):
    """Represents a v2 quantum network."""
    name = sa.Column(sa.String(255))
    ports = orm.relationship(Port, backref='networks')
    subnets = orm.relationship(Subnet, backref='networks')
    status = sa.Column(sa.String(16))
    admin_state_up = sa.Column(sa.Boolean)
    shared = sa.Column(sa.Boolean)

It defines ths name's limit is 255 characters. But there is no parameter check when create network.

Tags: api
Revision history for this message
Mark McClain (markmcclain) wrote :

This bug has come up previously and is a known issue. I expect that we'll address this in Icehouse as there will be proposals to update how we process API requests.

tags: added: api
Revision history for this message
yong sheng gong (gongysh) wrote :

got it, it will be fixed in Icehouse release

Changed in neutron:
status: New → Triaged
assignee: nobody → Mark McClain (markmcclain)
importance: Undecided → Medium
Revision history for this message
Abhishek Talwar (abhishek-talwar) wrote :

Hi Mark,

I have checked in the Icehouse release and the bug "String attributes should limit the length in API " still persists. So I wanted to know if you are still working with this bug as I am interested in fixing the issue.
Kindly let me know if i can work on this.

Revision history for this message
yong sheng gong (gongysh) wrote :

we are also facing this issue, looking forward to the fix. thanks.

Revision history for this message
Wei Wang (damon-devops) wrote :

I think what we need is declare an item in configuration file and set a default value in str validators, if we change api's param, it will be a big changllage for APIs have run so long time...

Revision history for this message
Wei Wang (damon-devops) wrote :

Any update?

Revision history for this message
Marios Andreou (marios-b) wrote :
Download full text (9.9 KiB)

I just tried the reproducer on a devstack box and it seems to have been fixed ( I get a 500 response when trying to create the network given in the example). I poked around a bit but couldn't find where it was fixed but the stack trace goes up all the way to oslo.db:

 2014-10-16 15:50:02.743 ERROR oslo.db.sqlalchemy.exc_filters [req-32367df8-1b00-4f72-a662-51cf89ca3486 demo 55bde6e3ca3342758d347c78dbafd67c] DBAPIError exception wrapped fr
om (DataError) (1406, "Data too long for column 'name' at row 1") 'INSERT INTO networks (tenant_id, id, name, status, admin_state_up, shared) VALUES (%s, %s, %s, %s, %s, %s)
' ('55bde6e3ca3342758d347c78dbafd67c', '305f3d5e-971a-43a0-a99e-2e62a6d8f1e7', 'test12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789
012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890',
 'ACTIVE', 1, 0)
2014-10-16 15:50:02.743 TRACE oslo.db.sqlalchemy.exc_filters Traceback (most recent call last):
2014-10-16 15:50:02.743 TRACE oslo.db.sqlalchemy.exc_filters File "/usr/lib/python2.7/site-packages/oslo/db/sqlalchemy/compat/handle_error.py", line 59, in _handle_dbapi_e
xception
2014-10-16 15:50:02.743 TRACE oslo.db.sqlalchemy.exc_filters e, statement, parameters, cursor, context)
2014-10-16 15:50:02.743 TRACE oslo.db.sqlalchemy.exc_filters File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 1024, in _handle_dbapi_exception
2014-10-16 15:50:02.743 TRACE oslo.db.sqlalchemy.exc_filters exc_info
2014-10-16 15:50:02.743 TRACE oslo.db.sqlalchemy.exc_filters File "/usr/lib64/python2.7/site-packages/sqlalchemy/util/compat.py", line 196, in raise_from_cause
2014-10-16 15:50:02.743 TRACE oslo.db.sqlalchemy.exc_filters reraise(type(exception), exception, tb=exc_tb)
2014-10-16 15:50:02.743 TRACE oslo.db.sqlalchemy.exc_filters File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/base.py", line 867, in _execute_context
2014-10-16 15:50:02.743 TRACE oslo.db.sqlalchemy.exc_filters context)
2014-10-16 15:50:02.743 TRACE oslo.db.sqlalchemy.exc_filters File "/usr/lib64/python2.7/site-packages/sqlalchemy/engine/default.py", line 324, in do_execute
2014-10-16 15:50:02.743 TRACE oslo.db.sqlalchemy.exc_filters cursor.execute(statement, parameters)
2014-10-16 15:50:02.743 TRACE oslo.db.sqlalchemy.exc_filters File "/usr/lib64/python2.7/site-packages/MySQLdb/cursors.py", line 174, in execute
2014-10-16 15:50:02.743 TRACE oslo.db.sqlalchemy.exc_filters self.errorhandler(self, exc, value)
2014-10-16 15:50:02.743 TRACE oslo.db.sqlalchemy.exc_filters File "/usr/lib64/python2.7/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
2014-10-16 15:50:02.743 TRACE oslo.db.sqlalchemy.exc_filters raise errorclass, errorvalue
2014-10-16 15:50:02.743 TRACE oslo.db.sqlalchemy.exc_filters DataError: (DataError) (1406, "Data too long for column 'name' at row 1") 'INSERT INTO networks (tenant_id, id,
name, status, admin_state_up, shared) VALUES (%s, %s, %s, %s, %s, %s)' ('55bde6e3ca3342758d347c78dbafd67c', '305f3d5e-971a-43a0-a99e-2e62...

Changed in neutron:
status: Triaged → Fix Released
Revision history for this message
Wei Wang (damon-devops) wrote :

Now we use oslo.db instead of openstack.common :-)

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Related questions

Remote bug watches

Bug watches keep track of this bug in other bug trackers.