axios: Request params are not getting merged with instance params
Describe the bug
Specific request params do not get merged with the instance default params.
To Reproduce
const instance = axios.create({
baseURL: "http://www.example.com",
params: {
q: "question",
}
});
instance.get("/page",
{
params: {
page: 2
}
}
)
What happens is that the request param object overrides the instance default param object. The instance no longer has a query param of q
.
Expected behavior
According to the docs, all configuration options are merged. https://github.com/axios/axios#instance-methods
I expected request to contain both q
and page
params. This is also how it was working in version 0.18.0, which is how I noticed.
Environment:
- Axios Version: 0.19.0
- OS: 10.14.5 (18F132)
- Browser: Node Express, and Chrome
- Browser: Node 10.15.0, Chrome Version 74.0.3729.169 (Official Build) (64-bit)
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 111
- Comments: 87 (9 by maintainers)
Commits related to this issue
- Fix unit test due to params merge policy change Ref: https://github.com/axios/axios/issues/2190 — committed to Gerhut/axios-debug-log by deleted user 5 years ago
- Fix unit test due to params merge policy change Ref: https://github.com/axios/axios/issues/2190 — committed to Gerhut/axios-debug-log by Gerhut 5 years ago
- :arrow_up: Updates. Downgraded Axios from 0.19.0 to 0.18.1 because of https://github.com/axios/axios/issues/2190 — committed to techouse/es6-boilerplate by techouse 5 years ago
- fix(axios): v0.19.0 cannot merge params - based on bug: https://github.com/axios/axios/issues/2190 - downgrade to the working version — committed to chenxeed/react-youtube-ui by chenxeed 5 years ago
- [RootAPI] getMe() function & workaround for axios/axios#2190 — committed to jcxldn/parkrun.js by jcxldn 4 years ago
Waiting for an official fix š
some kind of endless drama
upvote. just spent the afternoon chasing down this bug and came here to write an issue.
Still having this issue in 0.24.0.
const api = axios.create({ baseURL: url, params: { api_key, }, });
api(
/xxxxx, { method: "GET", params: config.query, });
config.query contains page param. It does not get merged with the instance params.
@magicdawn I think they messed up. I donāt get what they are waiting for to merge the fix. Pls @emilyemorehouse, help us with https://github.com/axios/axios/pull/2196 š!
woah! almost 1 year later!
Fix this already. this is really annoying. took me 15 minutes to figure this bug.
Downgrading to
0.18.1
fixed it for me as a workaround! That has the security vulnerability fixed.I have a same issue.
@adamreisnz sure I would opt for increments too but there was alot broken from 0.18.x to 0.19.x and the idea was to try make a 0.20.0 release stable with some of the most pressing stuff in that release. We only have 60 pull requests left, I have already worked through the rest and some of those 60 are either tagged as
wip
orv1
.I know it has been a long time but I would like to get it right this time and not just release and break more things cause at this point that is largely possible. Also the build will need wide spread testing before it goes public. I get the frustration but if we donāt get it stable and fix a ton of regressions we could release any number of increments, and still sit with over 200~ issues and 60~ pull requests that just sit there getting stale, as well as a still very broken Axios, maybe even more broken.
In addition I donāt control releases at the moment and when I started helping I promised to get together a build that would fix regressions and the most pressing issues as well as not breaking anything else that worked previously. I take this pretty serious and would like to do that.
I can however try and get a 0.18.x release with any security issues etc fixed if that is something that would help?
@markcarver Sure we could however Axios is seen as pre-release currently as without a v1 it looks to most people that Axios has not released a public API see SemVer PublicAPI. With v0.20.0 we would like to bring stability and fix most regressions from the 0.19.x branch as some problems presented in this branch as well as work on errors that are easy wins.
We also do need to clear the backlog of pull requests at the same time. It is very difficult to deal with 120 odd pull request where some of them were from as far back as 2017. I promise we will get to this issue, I am going nowhere and will be supporting and working on Axios as much as I can.
Thanks
I have re-opened but we wont be releasing a 0.19.3. We would like to gain stability in a 0.20 release that removes all the regression from 0.18.0 to 0.19.2.
v0.19.1
still has this bug š@janpantel Iām curious, why not just modify the params?
hope release soon , the issue made me pretty annoying
Thereās plenty of room in
0.x
to make additional releases before1.0.0
; you donāt have to cram everything into the next release. In fact, one could argue that would just make potential new bugs just harder to track down.I have always liked using axios. But the idea that this fix has been there for this long and no one can manage to assign it to a version is just a joke itās time to move on. Or get someone to manage this that actually wants to progress the product.
Jon Alberghini Director of Technology jon@legacyresearch.com o. 802-323-4558 | c. 802-323-4558 | www.legacyresearch.comhttp://www.legacyresearch.com
From: Evgeny notifications@github.com Sent: Thursday, April 23, 2020 10:59:32 AM To: axios/axios axios@noreply.github.com Cc: Jon Alberghini jon@legacyresearch.com; Comment comment@noreply.github.com Subject: Re: [axios/axios] Request params are not getting merged with instance params (#2190)
@techousehttps://github.com/techouse moving to alternatives is better solution.
ā You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/axios/axios/issues/2190#issuecomment-618445756, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AF6OZWIPRREAQP5OGY437X3ROBJVJANCNFSM4HRPA6AQ.
I think thereās just a lot of frustration building up, because we canāt use certain plugins (e.g. axios cache adapter) unless we downgrade and lock in Axios at v0.18, or roll our own (unmaintained) version and apply the fix there.
This has been the case for quite a few months now, and I think everyone is just keen to see at least some fixes released.
Is it not possible to port some of the currently applied fixes and release a 0.19.x so that at least we can use the latest codebase? If you intend to go through another 120 pull requests, I am afraid weāll be waiting a long time until we see a 0.20 or v1.
I would personally opt for a more incremental approach, if possible.
Seems the only possible solution rn is to downgrade.
Just downgrade to 0.18.0
The same problem is still exit since 2020. Does it run as designed or when can this issue be resolved?
Axios Version: 0.19.0
Thanks for providing such a useful lib!
This seems to also happen with
method
, if itās only specified in thecreate
call and not therequest
. Took me all day to figure that out, definitely a breaking change. (Should this be a separate issue, or is it part of the same general problem?)@serranoarevalo I think we can use
0.18.1
š@jasonsaayman tests are now passing (for what I assume the correct behavior is) in #2196
@jasonsaayman so far so good, 0.20.0 seems to be working well š
That would be awesome.
P.S.: We all appreciate the hard work youāre doing by maintaining a package that is intricate to so many web projects. š
The bug still exist! Canāt believeā¦
Same problem here using
axios@0.19.2
. Using interceptors as a workaround.Might be a hack, but you can also patch the get method for a created axios instance:
Took me a while to find this issue⦠annoying. Waiting on a fix too.
Hereās a running example ā https://runkit.com/philipbjorge/axios-regression
Was the intent to merge params with the default instance params? Because I can definitively say that this is not happening. The default params are being completely overridden. Iām using ^1.4.0.
Using interceptors is fine and all. That works. Itās just pretty unintuitive that axios instances donāt merge the runtime config with the instance config.
@adamreisnz could you test this branch: 0.20.0-beta.1
I found my way out using some deconstructing to separate the key param. Temporary code for sure, but since the merge is already done and 0.20.0 is underway, Iām really confident. Axios is still my way to go, even if I am experienced with fetch(). Things are usually so lean with Axios š
@khastation @raphaelbadawi @jonathanalberghini @techouse @AndyOGo
Alternatives:
I think itās closed because a fix has been merged and is supposed to be released in v0.20.0 . See here
@techouse moving to alternatives is better solution.
Unfortunately
fetch
is out as soon as you need progress events or cancelation support.I used interceptor as a workaround too, something like @cheelahim suggested:
But still waiting for a new version to fix this bug.
For everyone looking for a workaround you could use mine (might not apply to all):
npm i qs
https://github.com/axios/axios/blob/v0.19.0/lib/core/mergeConfig.js#L18-L22
the v0.19.0 code shows that
mergeConfig(axios_instance.defaults, config)
only the request config.params get used.Why a minor version not compitable with previous version? No test for this? I have to ask.