Skip to content

Commit

Permalink
Clarify some changed methods in migration guide
Browse files Browse the repository at this point in the history
  • Loading branch information
mesozoic committed Jul 31, 2023
1 parent 9695f4e commit 6083f71
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
23 changes: 23 additions & 0 deletions docs/source/migrations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,29 @@ See below for supported and unsupported patterns:
# to avoid situations where self.api and self.base don't align.
>>> table = Table(api, base_id, table_name) # [Api, Base, str]
You may need to change how your code looks up some pieces of connection metadata; for example:

.. list-table::
:header-rows: 1

* - Method/attribute in 1.5
- Method/attribute in 2.0
* - ``base.base_id``
- :data:`base.id <pyairtable.Base.id>`
* - ``table.table_name``
- :data:`table.name <pyairtable.Table.name>`
* - ``table.get_base()``
- :data:`table.base <pyairtable.Table.base>`
* - ``table.base_id``
- :data:`table.base.id <pyairtable.Base.id>`
* - ``table.table_url``
- :meth:`table.url <pyairtable.Table.url>`
* - ``table.get_record_url()``
- :meth:`table.record_url() <pyairtable.Table.record_url>`

There is no fully exhaustive list of changes; please refer to
:ref:`the API documentation <Module: pyairtable>` for a list of available methods and attributes.

Retry by default
----------------

Expand Down
3 changes: 3 additions & 0 deletions pyairtable/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ class Base:
Represents an Airtable base.
"""

#: The connection to the Airtable API.
api: "pyairtable.api.api.Api"

#: The base ID, in the format ``appXXXXXXXXXXXXXX``
id: str

def __init__(self, api: Union["pyairtable.api.api.Api", str], base_id: str):
Expand Down
16 changes: 12 additions & 4 deletions pyairtable/api/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ class Table:
>>> records = table.all()
"""

api: "pyairtable.api.api.Api"
#: The base that this table belongs to.
base: "pyairtable.api.base.Base"

#: Can be either the table name or the table ID (``tblXXXXXXXXXXXXXX``).
name: str

@overload
Expand Down Expand Up @@ -98,7 +100,6 @@ def __init__(
f" got ({type(api_key)}, {type(base_id)}, {type(table_name)})"
)

self.api = base.api
self.base = base
self.name = table_name

Expand All @@ -108,16 +109,23 @@ def __repr__(self) -> str:
@property
def url(self) -> str:
"""
Return the URL for this table.
Returns the URL for this table.
"""
return self.api.build_url(self.base.id, urllib.parse.quote(self.name, safe=""))

def record_url(self, record_id: RecordId, *components: str) -> str:
"""
Return the URL for the given record ID, with optional trailing components.
Returns the URL for the given record ID, with optional trailing components.
"""
return posixpath.join(self.url, record_id, *components)

@property
def api(self) -> "pyairtable.api.api.Api":
"""
Returns the same API connection as table's :class:`~pyairtable.Base`.
"""
return self.base.api

def get(self, record_id: RecordId, **options: Any) -> RecordDict:
"""
Retrieves a record by its ID.
Expand Down

0 comments on commit 6083f71

Please sign in to comment.