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

Disable aiohttp requoting of redirection URL #5459

Merged

Conversation

albertvillanova
Copy link
Member

@albertvillanova albertvillanova commented Jan 24, 2023

The library aiohttp performs a requoting of redirection URLs that unquotes the single quotation mark character: %27 => '

This is a problem for our Hugging Face Hub, which requires exact URL from location header.

Specifically, in the query component of the URL (https://netloc/path?query), the value for response-content-disposition contains %27:

response-content-disposition=attachment%3B+filename*%3DUTF-8%27%27sample.jsonl.gz%3B+filename%3D%22sample.jsonl.gz%22%3B

and after the requoting, the %27 characters get unquoted to ':

response-content-disposition=attachment%3B+filename*%3DUTF-8''sample.jsonl.gz%3B+filename%3D%22sample.jsonl.gz%22%3B

This PR disables the aiohttp requoting of redirection URLs.

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Jan 24, 2023

The documentation is not available anymore as the PR was closed or merged.

@albertvillanova
Copy link
Member Author

Comment by @lhoestq:

Do you think we need this in datasets if it's fixed on the moon landing side ? In the aiohttp doc they consider those symbols as "non-safe"

@albertvillanova
Copy link
Member Author

The lib requests does not perform that requote on redirect URLs.

Copy link
Member

@lhoestq lhoestq left a comment

Choose a reason for hiding this comment

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

I'm fine with aligning with requests - this way we have less differences between streaming and non-streaming.

Maybe add a comment on why you needed to add this parameter ?

@albertvillanova
Copy link
Member Author

albertvillanova commented Jan 25, 2023

Indeed, the requests library does perform a requoting, but this does not unquote %27:

In [1]: from requests.utils import requote_uri

In [2]: url = "https://netloc/path?param=param%27%27value"

In [3]: url
Out[3]: 'https://netloc/path?param=param%27%27value'

In [4]: requote_uri(url)
Out[4]: 'https://netloc/path?param=param%27%27value'

However, the aiohttp library uses yarl.ULR and this does unquote %27:

In [5]: from yarl import URL

In [6]: url
Out[6]: 'https://netloc/path?param=param%27%27value'

In [7]: str(URL(url))
Out[7]: "https://netloc/path?param=param''value"

If we pass requote_redirect_url=False to aiohttp, then it passes encoded=True to yarl.ULR: https://github.com/aio-libs/aiohttp/blob/4635161ee8e7ad321cca46e01ce5bfeb1ad8bf26/aiohttp/client.py#L578-L580

parsed_url = URL(
    r_url, encoded=not self._requote_redirect_url
)

which does not unquote %27:

In [8]: url
Out[8]: 'https://netloc/path?param=param%27%27value'

In [9]: str(URL(url, encoded=True))
Out[9]: 'https://netloc/path?param=param%27%27value'

@albertvillanova albertvillanova changed the title Fix requote redirect URL Fix requote redirection URL Jan 25, 2023
Copy link
Member

@lhoestq lhoestq left a comment

Choose a reason for hiding this comment

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

Thanks for the explanations :)

src/datasets/filesystems/compression.py Outdated Show resolved Hide resolved
@albertvillanova
Copy link
Member Author

See the issues we opened in the respective libraries:

@albertvillanova albertvillanova changed the title Fix requote redirection URL Fix aiohttp requoting of redirection URL Jan 27, 2023
@albertvillanova albertvillanova changed the title Fix aiohttp requoting of redirection URL Disable aiohttp requoting of redirection URL Jan 27, 2023
Co-authored-by: Quentin Lhoest <[email protected]>
@albertvillanova albertvillanova merged commit c4a4f96 into huggingface:main Jan 31, 2023
@albertvillanova albertvillanova deleted the fix-requote-redirect-url branch January 31, 2023 08:37
@github-actions
Copy link

Show benchmarks

PyArrow==6.0.0

Show updated benchmarks!

Benchmark: benchmark_array_xd.json

metric read_batch_formatted_as_numpy after write_array2d read_batch_formatted_as_numpy after write_flattened_sequence read_batch_formatted_as_numpy after write_nested_sequence read_batch_unformated after write_array2d read_batch_unformated after write_flattened_sequence read_batch_unformated after write_nested_sequence read_col_formatted_as_numpy after write_array2d read_col_formatted_as_numpy after write_flattened_sequence read_col_formatted_as_numpy after write_nested_sequence read_col_unformated after write_array2d read_col_unformated after write_flattened_sequence read_col_unformated after write_nested_sequence read_formatted_as_numpy after write_array2d read_formatted_as_numpy after write_flattened_sequence read_formatted_as_numpy after write_nested_sequence read_unformated after write_array2d read_unformated after write_flattened_sequence read_unformated after write_nested_sequence write_array2d write_flattened_sequence write_nested_sequence
new / old (diff) 0.012399 / 0.011353 (0.001047) 0.006388 / 0.011008 (-0.004620) 0.134173 / 0.038508 (0.095665) 0.037059 / 0.023109 (0.013949) 0.420697 / 0.275898 (0.144799) 0.473981 / 0.323480 (0.150502) 0.009857 / 0.007986 (0.001871) 0.004791 / 0.004328 (0.000463) 0.106886 / 0.004250 (0.102636) 0.044871 / 0.037052 (0.007818) 0.429843 / 0.258489 (0.171354) 0.461569 / 0.293841 (0.167728) 0.057285 / 0.128546 (-0.071261) 0.018809 / 0.075646 (-0.056837) 0.432613 / 0.419271 (0.013342) 0.058086 / 0.043533 (0.014553) 0.413064 / 0.255139 (0.157925) 0.444407 / 0.283200 (0.161207) 0.119102 / 0.141683 (-0.022581) 1.875954 / 1.452155 (0.423799) 1.916392 / 1.492716 (0.423676)

Benchmark: benchmark_getitem_100B.json

metric get_batch_of_1024_random_rows get_batch_of_1024_rows get_first_row get_last_row
new / old (diff) 0.267489 / 0.018006 (0.249483) 0.567554 / 0.000490 (0.567064) 0.005901 / 0.000200 (0.005701) 0.000134 / 0.000054 (0.000079)

Benchmark: benchmark_indices_mapping.json

metric select shard shuffle sort train_test_split
new / old (diff) 0.031248 / 0.037411 (-0.006164) 0.123014 / 0.014526 (0.108489) 0.140001 / 0.176557 (-0.036556) 0.191476 / 0.737135 (-0.545659) 0.141687 / 0.296338 (-0.154652)

Benchmark: benchmark_iterating.json

metric read 5000 read 50000 read_batch 50000 10 read_batch 50000 100 read_batch 50000 1000 read_formatted numpy 5000 read_formatted pandas 5000 read_formatted tensorflow 5000 read_formatted torch 5000 read_formatted_batch numpy 5000 10 read_formatted_batch numpy 5000 1000 shuffled read 5000 shuffled read 50000 shuffled read_batch 50000 10 shuffled read_batch 50000 100 shuffled read_batch 50000 1000 shuffled read_formatted numpy 5000 shuffled read_formatted_batch numpy 5000 10 shuffled read_formatted_batch numpy 5000 1000
new / old (diff) 0.637481 / 0.215209 (0.422272) 6.255969 / 2.077655 (4.178314) 2.559811 / 1.504120 (1.055691) 2.118154 / 1.541195 (0.576960) 2.079487 / 1.468490 (0.610997) 1.201079 / 4.584777 (-3.383698) 5.592625 / 3.745712 (1.846913) 5.143344 / 5.269862 (-0.126517) 2.764716 / 4.565676 (-1.800960) 0.142539 / 0.424275 (-0.281736) 0.015541 / 0.007607 (0.007934) 0.771407 / 0.226044 (0.545363) 7.631657 / 2.268929 (5.362728) 3.279684 / 55.444624 (-52.164940) 2.587566 / 6.876477 (-4.288911) 2.624622 / 2.142072 (0.482549) 1.427878 / 4.805227 (-3.377350) 0.257759 / 6.500664 (-6.242906) 0.078616 / 0.075469 (0.003147)

Benchmark: benchmark_map_filter.json

metric filter map fast-tokenizer batched map identity map identity batched map no-op batched map no-op batched numpy map no-op batched pandas map no-op batched pytorch map no-op batched tensorflow
new / old (diff) 1.609305 / 1.841788 (-0.232483) 18.258792 / 8.074308 (10.184484) 20.345242 / 10.191392 (10.153850) 0.267366 / 0.680424 (-0.413058) 0.047035 / 0.534201 (-0.487166) 0.568881 / 0.579283 (-0.010402) 0.662763 / 0.434364 (0.228399) 0.668927 / 0.540337 (0.128590) 0.755766 / 1.386936 (-0.631170)
PyArrow==latest
Show updated benchmarks!

Benchmark: benchmark_array_xd.json

metric read_batch_formatted_as_numpy after write_array2d read_batch_formatted_as_numpy after write_flattened_sequence read_batch_formatted_as_numpy after write_nested_sequence read_batch_unformated after write_array2d read_batch_unformated after write_flattened_sequence read_batch_unformated after write_nested_sequence read_col_formatted_as_numpy after write_array2d read_col_formatted_as_numpy after write_flattened_sequence read_col_formatted_as_numpy after write_nested_sequence read_col_unformated after write_array2d read_col_unformated after write_flattened_sequence read_col_unformated after write_nested_sequence read_formatted_as_numpy after write_array2d read_formatted_as_numpy after write_flattened_sequence read_formatted_as_numpy after write_nested_sequence read_unformated after write_array2d read_unformated after write_flattened_sequence read_unformated after write_nested_sequence write_array2d write_flattened_sequence write_nested_sequence
new / old (diff) 0.010017 / 0.011353 (-0.001336) 0.006816 / 0.011008 (-0.004192) 0.105038 / 0.038508 (0.066529) 0.038689 / 0.023109 (0.015580) 0.482113 / 0.275898 (0.206215) 0.540072 / 0.323480 (0.216592) 0.007738 / 0.007986 (-0.000248) 0.005134 / 0.004328 (0.000806) 0.102203 / 0.004250 (0.097953) 0.054080 / 0.037052 (0.017028) 0.501057 / 0.258489 (0.242568) 0.567186 / 0.293841 (0.273345) 0.060330 / 0.128546 (-0.068217) 0.020059 / 0.075646 (-0.055587) 0.123102 / 0.419271 (-0.296170) 0.063426 / 0.043533 (0.019893) 0.494171 / 0.255139 (0.239032) 0.538238 / 0.283200 (0.255039) 0.119613 / 0.141683 (-0.022069) 1.853728 / 1.452155 (0.401574) 1.984621 / 1.492716 (0.491904)

Benchmark: benchmark_getitem_100B.json

metric get_batch_of_1024_random_rows get_batch_of_1024_rows get_first_row get_last_row
new / old (diff) 0.282511 / 0.018006 (0.264505) 0.563190 / 0.000490 (0.562700) 0.000465 / 0.000200 (0.000265) 0.000086 / 0.000054 (0.000032)

Benchmark: benchmark_indices_mapping.json

metric select shard shuffle sort train_test_split
new / old (diff) 0.029267 / 0.037411 (-0.008144) 0.135618 / 0.014526 (0.121093) 0.146286 / 0.176557 (-0.030271) 0.188570 / 0.737135 (-0.548565) 0.155839 / 0.296338 (-0.140499)

Benchmark: benchmark_iterating.json

metric read 5000 read 50000 read_batch 50000 10 read_batch 50000 100 read_batch 50000 1000 read_formatted numpy 5000 read_formatted pandas 5000 read_formatted tensorflow 5000 read_formatted torch 5000 read_formatted_batch numpy 5000 10 read_formatted_batch numpy 5000 1000 shuffled read 5000 shuffled read 50000 shuffled read_batch 50000 10 shuffled read_batch 50000 100 shuffled read_batch 50000 1000 shuffled read_formatted numpy 5000 shuffled read_formatted_batch numpy 5000 10 shuffled read_formatted_batch numpy 5000 1000
new / old (diff) 0.671660 / 0.215209 (0.456451) 6.718775 / 2.077655 (4.641120) 3.004601 / 1.504120 (1.500481) 2.640504 / 1.541195 (1.099309) 2.666788 / 1.468490 (1.198298) 1.242655 / 4.584777 (-3.342122) 5.780119 / 3.745712 (2.034407) 3.247935 / 5.269862 (-2.021927) 2.114007 / 4.565676 (-2.451669) 0.147546 / 0.424275 (-0.276729) 0.014408 / 0.007607 (0.006801) 0.824407 / 0.226044 (0.598362) 8.278185 / 2.268929 (6.009257) 3.733463 / 55.444624 (-51.711161) 2.976732 / 6.876477 (-3.899745) 3.132758 / 2.142072 (0.990686) 1.446095 / 4.805227 (-3.359132) 0.258628 / 6.500664 (-6.242036) 0.085513 / 0.075469 (0.010043)

Benchmark: benchmark_map_filter.json

metric filter map fast-tokenizer batched map identity map identity batched map no-op batched map no-op batched numpy map no-op batched pandas map no-op batched pytorch map no-op batched tensorflow
new / old (diff) 1.702681 / 1.841788 (-0.139106) 18.725123 / 8.074308 (10.650815) 19.622808 / 10.191392 (9.431416) 0.215845 / 0.680424 (-0.464579) 0.029246 / 0.534201 (-0.504955) 0.554819 / 0.579283 (-0.024464) 0.630926 / 0.434364 (0.196562) 0.637663 / 0.540337 (0.097325) 0.837948 / 1.386936 (-0.548988)

@github-actions
Copy link

github-actions bot commented Feb 1, 2023

Show benchmarks

PyArrow==6.0.0

Show updated benchmarks!

Benchmark: benchmark_array_xd.json

metric read_batch_formatted_as_numpy after write_array2d read_batch_formatted_as_numpy after write_flattened_sequence read_batch_formatted_as_numpy after write_nested_sequence read_batch_unformated after write_array2d read_batch_unformated after write_flattened_sequence read_batch_unformated after write_nested_sequence read_col_formatted_as_numpy after write_array2d read_col_formatted_as_numpy after write_flattened_sequence read_col_formatted_as_numpy after write_nested_sequence read_col_unformated after write_array2d read_col_unformated after write_flattened_sequence read_col_unformated after write_nested_sequence read_formatted_as_numpy after write_array2d read_formatted_as_numpy after write_flattened_sequence read_formatted_as_numpy after write_nested_sequence read_unformated after write_array2d read_unformated after write_flattened_sequence read_unformated after write_nested_sequence write_array2d write_flattened_sequence write_nested_sequence
new / old (diff) 0.008540 / 0.011353 (-0.002813) 0.004538 / 0.011008 (-0.006470) 0.101507 / 0.038508 (0.062999) 0.029751 / 0.023109 (0.006641) 0.292608 / 0.275898 (0.016710) 0.354734 / 0.323480 (0.031254) 0.007430 / 0.007986 (-0.000556) 0.003365 / 0.004328 (-0.000964) 0.078703 / 0.004250 (0.074452) 0.034858 / 0.037052 (-0.002194) 0.303518 / 0.258489 (0.045029) 0.336523 / 0.293841 (0.042682) 0.033741 / 0.128546 (-0.094805) 0.011460 / 0.075646 (-0.064186) 0.319551 / 0.419271 (-0.099721) 0.041102 / 0.043533 (-0.002431) 0.295914 / 0.255139 (0.040775) 0.322142 / 0.283200 (0.038943) 0.084694 / 0.141683 (-0.056989) 1.481308 / 1.452155 (0.029153) 1.530271 / 1.492716 (0.037554)

Benchmark: benchmark_getitem_100B.json

metric get_batch_of_1024_random_rows get_batch_of_1024_rows get_first_row get_last_row
new / old (diff) 0.180516 / 0.018006 (0.162510) 0.405741 / 0.000490 (0.405251) 0.002806 / 0.000200 (0.002606) 0.000072 / 0.000054 (0.000018)

Benchmark: benchmark_indices_mapping.json

metric select shard shuffle sort train_test_split
new / old (diff) 0.023359 / 0.037411 (-0.014052) 0.096950 / 0.014526 (0.082424) 0.103991 / 0.176557 (-0.072566) 0.143700 / 0.737135 (-0.593435) 0.106764 / 0.296338 (-0.189575)

Benchmark: benchmark_iterating.json

metric read 5000 read 50000 read_batch 50000 10 read_batch 50000 100 read_batch 50000 1000 read_formatted numpy 5000 read_formatted pandas 5000 read_formatted tensorflow 5000 read_formatted torch 5000 read_formatted_batch numpy 5000 10 read_formatted_batch numpy 5000 1000 shuffled read 5000 shuffled read 50000 shuffled read_batch 50000 10 shuffled read_batch 50000 100 shuffled read_batch 50000 1000 shuffled read_formatted numpy 5000 shuffled read_formatted_batch numpy 5000 10 shuffled read_formatted_batch numpy 5000 1000
new / old (diff) 0.416966 / 0.215209 (0.201757) 4.145601 / 2.077655 (2.067946) 1.838258 / 1.504120 (0.334139) 1.629396 / 1.541195 (0.088201) 1.649707 / 1.468490 (0.181217) 0.689624 / 4.584777 (-3.895153) 3.414584 / 3.745712 (-0.331129) 1.874295 / 5.269862 (-3.395566) 1.251930 / 4.565676 (-3.313746) 0.081782 / 0.424275 (-0.342493) 0.012868 / 0.007607 (0.005261) 0.523904 / 0.226044 (0.297859) 5.251032 / 2.268929 (2.982104) 2.301549 / 55.444624 (-53.143075) 1.942110 / 6.876477 (-4.934367) 2.023014 / 2.142072 (-0.119058) 0.816492 / 4.805227 (-3.988736) 0.150107 / 6.500664 (-6.350558) 0.065118 / 0.075469 (-0.010351)

Benchmark: benchmark_map_filter.json

metric filter map fast-tokenizer batched map identity map identity batched map no-op batched map no-op batched numpy map no-op batched pandas map no-op batched pytorch map no-op batched tensorflow
new / old (diff) 1.226433 / 1.841788 (-0.615355) 13.852569 / 8.074308 (5.778261) 13.862779 / 10.191392 (3.671387) 0.146361 / 0.680424 (-0.534062) 0.028652 / 0.534201 (-0.505549) 0.398251 / 0.579283 (-0.181032) 0.403590 / 0.434364 (-0.030774) 0.492184 / 0.540337 (-0.048154) 0.581040 / 1.386936 (-0.805896)
PyArrow==latest
Show updated benchmarks!

Benchmark: benchmark_array_xd.json

metric read_batch_formatted_as_numpy after write_array2d read_batch_formatted_as_numpy after write_flattened_sequence read_batch_formatted_as_numpy after write_nested_sequence read_batch_unformated after write_array2d read_batch_unformated after write_flattened_sequence read_batch_unformated after write_nested_sequence read_col_formatted_as_numpy after write_array2d read_col_formatted_as_numpy after write_flattened_sequence read_col_formatted_as_numpy after write_nested_sequence read_col_unformated after write_array2d read_col_unformated after write_flattened_sequence read_col_unformated after write_nested_sequence read_formatted_as_numpy after write_array2d read_formatted_as_numpy after write_flattened_sequence read_formatted_as_numpy after write_nested_sequence read_unformated after write_array2d read_unformated after write_flattened_sequence read_unformated after write_nested_sequence write_array2d write_flattened_sequence write_nested_sequence
new / old (diff) 0.006859 / 0.011353 (-0.004494) 0.004632 / 0.011008 (-0.006376) 0.076653 / 0.038508 (0.038145) 0.027865 / 0.023109 (0.004755) 0.354472 / 0.275898 (0.078573) 0.385462 / 0.323480 (0.061982) 0.005125 / 0.007986 (-0.002861) 0.003420 / 0.004328 (-0.000909) 0.076018 / 0.004250 (0.071768) 0.040197 / 0.037052 (0.003144) 0.353675 / 0.258489 (0.095186) 0.394911 / 0.293841 (0.101070) 0.032909 / 0.128546 (-0.095637) 0.011713 / 0.075646 (-0.063933) 0.085921 / 0.419271 (-0.333350) 0.044462 / 0.043533 (0.000929) 0.349997 / 0.255139 (0.094858) 0.375207 / 0.283200 (0.092008) 0.091288 / 0.141683 (-0.050394) 1.536515 / 1.452155 (0.084361) 1.581878 / 1.492716 (0.089162)

Benchmark: benchmark_getitem_100B.json

metric get_batch_of_1024_random_rows get_batch_of_1024_rows get_first_row get_last_row
new / old (diff) 0.273284 / 0.018006 (0.255277) 0.424457 / 0.000490 (0.423967) 0.044659 / 0.000200 (0.044459) 0.000247 / 0.000054 (0.000192)

Benchmark: benchmark_indices_mapping.json

metric select shard shuffle sort train_test_split
new / old (diff) 0.025473 / 0.037411 (-0.011938) 0.100014 / 0.014526 (0.085488) 0.108551 / 0.176557 (-0.068006) 0.147913 / 0.737135 (-0.589223) 0.112729 / 0.296338 (-0.183610)

Benchmark: benchmark_iterating.json

metric read 5000 read 50000 read_batch 50000 10 read_batch 50000 100 read_batch 50000 1000 read_formatted numpy 5000 read_formatted pandas 5000 read_formatted tensorflow 5000 read_formatted torch 5000 read_formatted_batch numpy 5000 10 read_formatted_batch numpy 5000 1000 shuffled read 5000 shuffled read 50000 shuffled read_batch 50000 10 shuffled read_batch 50000 100 shuffled read_batch 50000 1000 shuffled read_formatted numpy 5000 shuffled read_formatted_batch numpy 5000 10 shuffled read_formatted_batch numpy 5000 1000
new / old (diff) 0.448162 / 0.215209 (0.232953) 4.472701 / 2.077655 (2.395046) 2.078384 / 1.504120 (0.574264) 1.861292 / 1.541195 (0.320097) 1.920482 / 1.468490 (0.451991) 0.706968 / 4.584777 (-3.877809) 3.433109 / 3.745712 (-0.312603) 1.898684 / 5.269862 (-3.371178) 1.174375 / 4.565676 (-3.391302) 0.083666 / 0.424275 (-0.340609) 0.012388 / 0.007607 (0.004781) 0.546011 / 0.226044 (0.319966) 5.487514 / 2.268929 (3.218585) 2.534124 / 55.444624 (-52.910500) 2.168441 / 6.876477 (-4.708036) 2.203458 / 2.142072 (0.061386) 0.813333 / 4.805227 (-3.991894) 0.153169 / 6.500664 (-6.347495) 0.067151 / 0.075469 (-0.008318)

Benchmark: benchmark_map_filter.json

metric filter map fast-tokenizer batched map identity map identity batched map no-op batched map no-op batched numpy map no-op batched pandas map no-op batched pytorch map no-op batched tensorflow
new / old (diff) 1.277815 / 1.841788 (-0.563972) 13.920545 / 8.074308 (5.846237) 13.473801 / 10.191392 (3.282409) 0.129035 / 0.680424 (-0.551389) 0.016737 / 0.534201 (-0.517464) 0.388413 / 0.579283 (-0.190870) 0.388785 / 0.434364 (-0.045579) 0.481735 / 0.540337 (-0.058602) 0.576390 / 1.386936 (-0.810546)

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