gtalarico / pyairtable

Python Api Client for Airtable
https://pyairtable.readthedocs.io
MIT License
786 stars 139 forks source link

ORM get all() entries returns a json, not a Model #188

Closed NicoHood closed 1 year ago

NicoHood commented 2 years ago

Talking about this: https://github.com/gtalarico/pyairtable/blob/main/pyairtable/orm/model.py#L234-L238

This confuses me, as it really does not help for the ORM. I am currently trying to download existing data as Model. I thought that the all() function would do that, but it returns the json data, which is not what we want.

NicoHood commented 2 years ago

Isnt that also what the type annotation says? I think we need to wrap it into the from_record() function.

larsakerson commented 2 years ago

This would be nice!

gtalarico commented 2 years ago

I don't recall if I had a reason for doing it that way or if it was just a mistake. Probably the latter :)

Easy workaround until this is fixed: models = [model.from_record(record) for record in model.all()]

Actual fix:

    @classmethod
    def all(cls, **kwargs) -> List[T]:
        """Returns all records for this model. See :meth:`~pyairtable.api.Api.all`"""
        table = cls.get_table()
        return [self.from_record(record) for record in table.all(**kwargs)]