Skip to content

[Tables] autorest generated code incompatible with Python 3 #44869

@alexleach

Description

@alexleach
  • Package Name: azure-data-tables
  • Package Version: 12.7.0
  • Operating System: Mac OS
  • Python Version: 3.14

Describe the bug

TLDR; Please re-run autorest to update the auto-generated azure-data-table Swagger code, as per #31862

It was last run in October 2023, and it seems that back then autorest generated Python 2 code when this library is meant only to support Python 3?


I noticed in _serialization.py, it is assumed unicode is a global type. For example, in RawDeserializer.deserialize_from_text:-

if isinstance(data, unicode):  # type: ignore
    # If I'm Python 2.7 and unicode XML will scream if I try a "fromstring" on unicode string
    data_as_str = data_as_str.encode(encoding="utf-8")  # type: ignore

And in RawDeserializer.serialize_unicode:-

if isinstance(data, unicode):  # type: ignore
    # Don't change it, JSON and XML ElementTree are totally able
    # to serialize correctly u'' strings
    return data

However:-

Since Python 3.0, the language’s str type contains Unicode characters, meaning any string created using "unicode rocks!", 'unicode rocks!', or the triple-quoted string syntax is stored as Unicode.

Ref: https://docs.python.org/3/howto/unicode.html#the-string-type

Therefore, since Python 3.0, unicode does not exist:

$ python3 -c 'print(isinstance("foo", unicode))'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
    print(isinstance("foo", unicode))
                            ^^^^^^^
NameError: name 'unicode' is not defined

To Reproduce
Steps to reproduce the behavior:

  1. I've not a full MWE, but I have this method:-
    async def get_by_site_id(self, site_id: str) -> Optional[Site]:
        entities = list(self._table.query_entities(f"RowKey eq '{site_id}'", results_per_page=1))
        if not entities:
            return None
        return Site.from_entity(entities[0])

And this traceback:-

Exception has occurred: NameError
name 'unicode' is not defined
  File "/usr/local/lib/python3.14/site-packages/azure/data/tables/_generated/_serialization.py", line 874, in serialize_unicode
    if isinstance(data, unicode):  # type: ignore
                        ^^^^^^^
  File "/usr/local/lib/python3.14/site-packages/azure/data/tables/_generated/_serialization.py", line 857, in serialize_basic
    return cls.serialize_unicode(data)
  File "/usr/local/lib/python3.14/site-packages/azure/data/tables/_generated/_serialization.py", line 812, in serialize_data
    return self.serialize_basic(data, data_type, **kwargs)
  File "/usr/local/lib/python3.14/site-packages/azure/data/tables/_generated/_serialization.py", line 727, in url
    output = self.serialize_data(data, data_type, **kwargs)
  File "/usr/local/lib/python3.14/site-packages/azure/data/tables/_generated/operations/_operations.py", line 925, in query_entities
    "url": self._serialize.url("self._config.url", self._config.url, "str", skip_quote=True),
  File "/usr/local/lib/python3.14/site-packages/azure/core/tracing/decorator.py", line 119, in wrapper_use_tracer
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.14/site-packages/azure/data/tables/_models.py", line 351, in _get_next_cb
    return self._command(
  File "/usr/local/lib/python3.14/site-packages/azure/core/paging.py", line 82, in __next__
    self._response = self._get_next(self.continuation_token)
  File "/usr/local/lib/python3.14/site-packages/azure/core/paging.py", line 136, in __next__
    return next(self._page_iterator)
  File "/Users/alex/Code/my_app/core/storage/azure_tables.py", line 108, in get_by_site_id
    entities = list(self._table.query_entities(f"RowKey eq '{site_id}'", results_per_page=1))

Expected behavior
The bug to be in my code, not the azure-data-tables Python SDK! 😲

Screenshots
N/A

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    customer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-triageWorkflow: This is a new issue that needs to be triaged to the appropriate team.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions