Selecting the target deck for an import

In my reverso add-on I select a deck and import using the code below, but it never gets to the deck I select.

I believe it is influenced by the preference directive “Default deck” and I set “Add to the current deck”, nevertheless I never managed to determine the target deck.

Can somebody explain what’s the ratio and if it is any possible? thanks in advance.

Here is the code I’m using now:

    def import_data(self, words=None, deck_name=None):
        self.notes = words
        self.get_model()
        self.select_deck(deck_name or self.config.get('deck_name', 'Reverso'))
        temp_file = tempfile.NamedTemporaryFile(
            encoding="utf-8", mode="w+", prefix='reverso_', suffix=".csv", delete=False)
        self.get_notes_as_csv(temp_file)
        self.import_notes(temp_file.name)

    def select_deck(self, deck_name):
        """Select the deck in argument"""
        # we need to select the deck so that import will go there by default
        did = mw.col.decks.id(deck_name)
        mw.col.decks.select(did)
        # anki defaults to the last note type used in the selected deck
        m = mw.col.models.byName(self.NOTE_NAME)
        deck = mw.col.decks.get(did)
        ## mid? che è? che serve?
        deck['mid'] = m['id']
        mw.col.decks.save(deck)
        # and puts cards in the last deck used by the note type
        m['did'] = did

    def import_notes(self, csv_filename):
        """
        Implements `non_interactive` mode
        """
        # deck has already been selected
        # import into the collection
        ti = TextImporter(mw.col, csv_filename)
        mw.reset()
        # TextImporter will update card with same srcText
        ti.initMapping()
        ti.run()