The Masoretic Text of Genesis complicates the issue further because its last verse of Ch. 37 says that it was Medanites (meḏānîm), not Midianites, who sold Joseph to Potiphar in Egypt. This version is not at all popular for English translation (nor, from what I've seen so far, for French, Spanish or most other languages either). The only translations that I've encountered which render the word unabashedly as "Medanites" are The Scriptures (ISR) 1998, and Young's Literal Translation. The New King James Version mentions the Masoretic Textual variant in its footnote of the verse in question. At any rate the MT, so it would seem, is introducing a third group of people into the narrative, just before the story transitions to a different setting.
There are some noteworthy ancestral details provided earlier in the same book, which may present a certain kind of solution to the issue. On the broader face of it there is the crime of a sort of violence inflicted upon a kinsman in view here. The names of these groups (including even the Medanites, who are never again mentioned in the Bible) should by this point be familiar to the reader of Genesis because each of them is descended from a son of Abraham. Joseph and his brothers are grandsons of Isaac while the Ishmaelites, Midianites and Medanites would trace themselves, respectively, to Isaac's half-brothers Ishmael, Midian and Medan, each of whom appears together with Isaac in the first 13 verses of Ch. 25.
Therefore, familially speaking, whether we equate these three groups of traders with one another or not, they would all be Joseph's own second cousins, who are buying and selling him into slavery. Ch. 37 makes no mention of familial recognition between Joseph's brothers and the merchants, so it is not possible to say whether the sellers and the buyers acknowledged each other as close relatives or not, but it doesn't rule it out. (Thematic consideration could be made for the fact that towards the beginning of the book [Ch. 4], still in the same family, Cain, the first man to ever have a brother, kills his own brother.)
Additionally, there is narrative symmetry in the connections to Egypt and slavery:
Ishmael's mother Hagar is an Egyptian who is a slave of Isaac's mother Sarah. How Hagar comes to be in Sarah's possession is not mentioned but presumably she is acquired in Ch. 12 during the Negev famine from which Sarah and her husband Abraham seek refuge in Egypt.
In Ch. 16 Sarah gives Hagar to Abraham for him to sire a son upon her, and from their union Ishmael is born. From then on there is friction and conflict between Sarah on the one hand, and Hagar and Ishmael on the other.
And now in Ch. 37 Sarah's great-grandson Joseph is bought into slavery by Ishmael's offspring, who sell him into the same land that their mother Hagar came from, and from which she herself may have been bought.
Following the lines of ancestry along gives perspective to the fact that distinctions between ethnic groups are extremely porous social artifices with ultimately no objectively clear boundaries. Indeed some pains are evidently taken to indicate as much even in the preceding chapter (#36), which begins by mentioning that Joseph's uncle Esau, the ancestor of the Edomites, is married to his own cousin, the daughter of Ishmael. Their son Reuel becomes the father of an Edomite tribe which therefore is part Ishmaelite.
So far in the family tree there has been a history of other cousins marrying each other too, as well as uncles marrying nieces. Similar relations may have occurred among the children and grandchildren of Ishmael, Midian and Medan such that it rendered them at least partly indistinguishable. Indeed, it may even be a good place to look for where the wives of Joseph's brothers came from. It would be well in stride with the family culture for them to have married the other descendants of Abraham. (Judah's Canaanite wife and Joseph's Egyptian wife are the only ones specified and perhaps only because they are anomalous.)
The Pulpit Commentary on Genesis 37 has a handful of scholarly attempts at solving the apparent puzzle of who is supposed be who among the buyers of Joseph, one of which is that they were part of a caravan composed of men from various nations working together or
that the Midianites, Ishmaelites, and Medanites were often confounded
from their common parentage and closely similar habits (Keil); that
the narrator did not intend to lay stress upon the nationality, but
upon the occupation, of the travelers (Havernick); that the
proprietors of the caravan were Ishmaelites, and the company attending
it Midianites or Medanites (Lange); that the Ishmaelites were the
genus, and the Midianites and Medanites the species, of the same
nation (Rosenmüller, Quarry); that the Midianites or Medanites were
the actual purchasers of Joseph, while the caravan took its name from
the Ishmaelites, who formed the larger portion of it (Murphy).