Comments (5)
On further inspection, it looks like we do already support timeout
and typecast
as model options (here and here). So what's left here, imho, is:
- Support a
use_field_ids
option inModel.Meta
that forcesreturn_fields_by_field_id=True
. - Disallow kwargs like
cell_format
orreturn_fields_by_field_id
inModel.all()
from pyairtable.
I can definitely see a rationale for putting Api
kwargs into the model configuration, since otherwise there's no way to provide them.
For the table kwargs, I think it's worth going case by case:
- 👍
return_fields_by_field_id
– I suppose if someone wants to set up the ORM to use field IDs instead of field names, this might be useful. It would need some testing to see if there are other side effects. Right now if someone passed this toModel.all()
it would probably just break. - 👍
typecast
– I candidly can't see it making a lot of sense to turn this off, especially if you're type checking your code (which will prevent you from e.g. writing astr
to aDatetimeField
). But I also don't see a lot of harm in making this a model configuration option. - 👎
fields
– it does not make sense to pass this toModel.all()
. If anything, the Model class should be passing this automatically based on how its own fields have been configured, so it doesn't get more data from the API than it actually needs. - 👎
sort
,page_size
,max_records
– I definitely don't think these belong in the model configuration since they're going to be so specific to a particular use case. They should stay as a kwarg for theall()
method. - ❓
view
andformula
– I'm not sure these belong in the model configuration, since you can still create records which don't match the view/formula conditions. So it could lead to a situation where you create a record through the model, callsave()
, and then can't retrieve or fetch it later. - 👎
cell_format
– using this makes the ORM sort of irrelevant, since everything will come back as astr
. I could be convinced otherwise if someone comes in with a legit use case. - 👎
time_zone
anduser_locale
are only relevant ifcell_format="string"
. IMHO these features aren't that useful; it should be up to the client application, not the Airtable server, to localize the data it receives from the API.
from pyairtable.
return_fields_by_field_id
does not appear to break Model.all()
, and I think it might be the only justifiable addition to the model configuration.
I am not understanding what typecast
does currently in the ORM code. Is it only on Model.save()
that it checks types?
from pyairtable.
As I understand it, typecast=True
means that Airtable will make best effort to convert a string value to the appropriate data type. That means you can submit "2024-03-18"
and it will coerce to a date; you can submit a record name to a linked record field, and Airtable will attempt to find the existing record (or create a new one). I'm ambivalent on whether this should default to true or false, but I think making it a Meta option is sensible. It's really only meaningful if you're not using mypy to type-check your code, though.
I don't think return_fields_by_field_id
works in the current codebase because the return values won't match any of the existing field descriptors. I tested this here:
>>> import os
>>> from pyairtable.orm import Model, fields as f
>>> class Contact(Model):
... class Meta:
... api_key = os.environ['AIRTABLE_API_KEY']
... base_id = 'appaPqizdsNHDvlEm'
... table_name = 'Contact'
... name = f.TextField('First Name')
...
>>> print(Contact.all()[0].name)
Alice
>>> print(Contact.all(return_fields_by_field_id=True)[0].name)
None
So I think this only makes sense as a Meta configuration option, indicating the model is configured with field IDs instead of field names. I don't think we should allow passing the return_fields_by_field_id
parameter to Model.all()
at all.
These would both be welcome additions to the 3.0 release :)
from pyairtable.
Sounds good, I agree with everything said.
from pyairtable.
Related Issues (20)
- to_airtable_value() might not be correct for date and datetime values HOT 2
- Add more formulas HOT 2
- Update does not accept return_fields_by_field_id parameter HOT 8
- Rate limit API requests without forcing retries HOT 4
- get_table_schema fails when the api.table is initialized with the table's ID HOT 2
- Error using sample HOT 2
- Implement missing formulas HOT 2
- 2.2 release missing table.update_field HOT 1
- Can I just replace my API key with Personal Access token in legacy code ? HOT 1
- LookupField referencing a LinkField returns id rather than entity HOT 2
- Dynamic solution to formulas HOT 1
- One to many search difficulties HOT 4
- Error on `base.create_table` HOT 1
- ORM Batch Save Strategy HOT 1
- There should be a way to always set `return_fields_by_field_id` to `True` on all supported calls. HOT 5
- Issue with creating multipleRecordLinks '0.options.isReversed is missing' HOT 2
- CSV import HOT 4
- In Table.get can get a record regardless of the table ID HOT 3
- TypeError: ForwardRef._evaluate() missing 1 required keyword-only argument: 'recursive_guard' HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pyairtable.