biggest culprit is usually decomposing food waste.
Common attractants include:
Meat scraps
Fish
Chicken bones
Leftover cooked food
Fruit
Vegetables
Dairy products
Food-soaked paper
Pet food
Wet garbage
Food residue inside the bin
Warm weather makes the problem even more likely because decomposition happens faster and flies become more active.
A tightly closed trash bag doesn’t necessarily solve the problem either. If flies get access before the bag is tied, or if eggs are already present, larvae can develop