Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch back to default Faraday encoder and change list-records call to POST #96

Merged
merged 1 commit into from
Jan 11, 2023

Conversation

theblang
Copy link
Contributor

@theblang theblang commented Jan 4, 2023

See comments below. I smoke tested:

  1. all (with a single and multiple value fields array)
  2. find

@theblang theblang marked this pull request as draft January 5, 2023 03:01
@theblang theblang marked this pull request as ready for review January 5, 2023 21:10
@@ -21,9 +19,7 @@ def connection
headers: {
"Authorization" => "Bearer #{api_key}",
"User-Agent" => "Airrecord/#{Airrecord::VERSION}",
"X-API-VERSION" => "0.1.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by, this is no longer required and is out of date.

},
request: { params_encoder: Airrecord::QueryString }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Airtable expects that arrays in query strings be encoded with indices.

Turns out this isn't the case anymore (checked various examples in the API docs). And interestingly, it caused a bizarre issue with our list-records call where increasing the fields param count to about 22+ (which is still well under the 16k request character limit) would cause a 422 Invalid request: parameter validation failed. Check your request data.. So I just gutted Airrecord::QueryString to switch back to the default Faraday encoding, which is ?foo[]=1&foo[]=2 (interesting side note, they have actually added the ability to specify indexes in the encoding). After switching, our list-records call started working again.

Superseding all of this is the fact that this PR is switching the list-records call to POST, which also fixes our issue. But seems worth it to stop maintaining a custom encoder if we don't have to.

@@ -33,7 +29,7 @@ def connection
end

def escape(*args)
QueryString.escape(*args)
CGI.escape(*args)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This used to be URI.escape before the change to our custom encoder. That no longer exists, but CGI.escape seems appropriate for our use here. See this SO answer.

path = "/v0/#{base_key}/#{client.escape(table_name)}"
response = client.connection.get(path, options)
path = "/v0/#{base_key}/#{client.escape(table_name)}/listRecords"
response = client.connection.post(path, options.to_json, { 'Content-Type' => 'application/json' })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conversion to POST as per the notes in #95

@Meekohi
Copy link
Collaborator

Meekohi commented Jan 6, 2023

Looks solid to me but I'm not in a position to test this library myself anymore. @theblang if you're confident I'll go ahead and merge?

@Meekohi
Copy link
Collaborator

Meekohi commented Jan 11, 2023

@sirupsen maybe you can do a quick smoke test on this?

@theblang
Copy link
Contributor Author

theblang commented Jan 11, 2023

@Meekohi About to do some heavy smoke testing in our internal code that uses this PR's changes, so I'll report back once I'm finished!

Update: Just finished a ton of internal testing that's using these changes, and it LGTM!

@sirupsen
Copy link
Owner

yeah I don't have anything in production on airrrecord anymore to smoke test with unfortunately

@theblang theblang changed the title Switch back to default Faraday encoder and change list-records call to POST. Fixes #95 Switch back to default Faraday encoder and change list-records call to POST Jan 11, 2023
@theblang
Copy link
Contributor Author

I just noticed that Development section of the sidebar! So I removed "Fixes #95" from the commit message. But I think one of you will need to add it to Development?

@Meekohi
Copy link
Collaborator

Meekohi commented Jan 11, 2023

Sounds like I nominate @theblang to be the new maintainer ;D I'm gonna go ahead and merge.

@Meekohi Meekohi merged commit c1dec35 into sirupsen:master Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants