Tamar’s sons

Week 2 Genesis 25-42

There’s a weird story in Genesis 38.
Not weird because of the strange cultural practices.
For me it’s weird because I read the story and ask why is it in the bible at all?
Judah was one of Jacob’s sons and one day during sheep-shearing season he happened to pass a sex-worker who was sitting by the Enaim gateway on the road to Timnah. Turned out she was not a temple girl-for-hire but Judah’s own daughter-in-law, who had veiled herself and was working a scam to trick Judah into a sexual transaction because he had backed out of a bargain to let her marry his last living son. It was a dangerous con and Tamar barely escaped with her life. But things panned out. Judah would have been a bit embarrassed I guess, but admitted he was in the wrong. Tamar had Judah’s twins – Perez and Zerah. 
When I see a spicy story like this in the bible I have a gut response: this is stupid. If I’m lucky I pass on through my gut on the way to my head and ask why is this story here?
I don’t find out right now why this story is here because the writer doesn’t tell me. So I put the story on hold. I try to resist saying this is stupid, and I wait for further developments (even though it’s a lot easier to throw it in the Stupid Bin and just move on).