SwiftService list in 3.13.1 throws "No tenant specified" on iterating with __iter__ through results

Bug #1970732 reported by David Lassig
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-swiftclient
New
Undecided
Unassigned

Bug Description

I tried to use the example in https://opendev.org/openstack/python-swiftclient/src/tag/3.13.1/examples/list.py with python-swiftclient in version 3.13.1

Converting to a minimal example to focus the bug:

```python
from swiftclient.client import Connection
from swiftclient.service import SwiftService

_authurl = XXX
_key = XXX
_tenant = 'my_tenant'

minimum_size = 10*1024**2

conn = Connection(
    preauthurl =_authurl,
    preauthtoken =_key,
    os_options = {"tenant_name":_tenant,
                  "tenant_id":_tenant,
                  }
)

resp_headers, containers = conn.get_account()
for container in containers:
    print(container)

with SwiftService() as swift:
    # works as expected
    list_parts_gen = swift.list(container=conn)
    next(list_parts_gen)

    # will raise error on iterating
    list_parts_gen = swift.list(container=conn)
    for list in list_parts_gen:
        print(list)
        break
```

On execution the __next__ on the iterator works as expected:

```json
{'bytes': 1522284, 'hash': 'e4076afb2c4eaa7722558f804c7ac069', 'name': 'Super Albar.stl', 'content_type': 'application/sla', 'last_modified': '2022-04-26T10:29:36.274230'}
```

But doing the same with __iter__ on the iterator raises:

```json
{'action': 'list_container_part', 'container': <swiftclient.client.Connection object at 0x7f2470045b20>, 'prefix': None, 'success': False, 'marker': '', 'version_marker': '', 'error': ClientException('No tenant specified'), 'traceback': 'Traceback (most recent call last):\n File "/usr/local/lib/python3.8/site-packages/swiftclient/service.py", line 1015, in _list_container_job\n _, items = conn.get_container(\n File "/usr/local/lib/python3.8/site-packages/swiftclient/client.py", line 1935, in get_container\n return self._retry(None, get_container, container, marker=marker,\n File "/usr/local/lib/python3.8/site-packages/swiftclient/client.py", line 1845, in _retry\n self.url, self.token = self.get_auth()\n File "/usr/local/lib/python3.8/site-packages/swiftclient/client.py", line 1789, in get_auth\n self.url, self.token = get_auth(self.authurl, self.user, self.key,\n File "/usr/local/lib/python3.8/site-packages/swiftclient/client.py", line 769, in get_auth\n raise ClientException(\'No tenant specified\')\nswiftclient.exceptions.ClientException: No tenant specified\n', 'error_timestamp': 1651140546.702744}
```

Actually the tenant is defined in the container object itself but much more important, there shouldn't a difference in handling the iterator with __next__ or __iter__. I tried to find the source for this problem but wasn't able to.

I tried to add in the SwiftService() object after initialization with the necessary `os_options` dict but this leads to Type error.

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

Other bug subscribers

Remote bug watches

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