Florian Guily

    Florian Guily

    4 months ago
    hey, i'm trying to insert data in mysql using the
    MySqlExecute
    task. I have no error (i had some but i fixed them) but the row i try to insert isn't showing in the table. I can do it with the same user from mysql workbench and the
    MySqlExecute
    task return 1 as expected. I don't understand why, maybe i'm doing something wrong. Here is a code example of my task:
    @task
    def set_new_date():
        logger = prefect.context.get("logger")
        new_date = datetime.date.today().strftime("%Y-%m-%d")
        query = f"""
            INSERT INTO `name`.`table_name` (`name`, `value`) VALUES ('name', '{new_date}');
        """
        result = MySQLExecute(
            db_name="name",
            user="user",
            password="pwd",
            host="host",
            port=3306,
            query=query).run()
        <http://logger.info|logger.info>("New date is {}".format(new_date))
        <http://logger.info|logger.info>("Query results is {}".format(result))
    Kevin Kho

    Kevin Kho

    4 months ago
    It’s hard to tell. This looks right. When happens when you use
    MySQLExecute
    outside of a task?
    Florian Guily

    Florian Guily

    4 months ago
    I tried directly inside the flow like this:
    query = f"""
            INSERT INTO `name`.`table_name` (`name`, `value`) VALUES ('name', '2022-05-12');
        """
        flow.add_task(MySQLExecute(
            db_name="name",
            user="user",
            password="pwd",
            host="host",
            port=3306,
            query=query))
    And same thing. The task is marked as successful in the logs but the row is not showing up
    Kevin Kho

    Kevin Kho

    4 months ago
    Could you try the Python code under the hood and seeing if it works.
    Anna Geller

    Anna Geller

    4 months ago
    this is sort of a duplicated question - I answered here
    Florian Guily

    Florian Guily

    4 months ago
    oh ok thanks didn't see your reply ! i'll try that
    Jeez the prob was that the commit arg had to be set on True for the query to be executed...
    Problem solved thanks !
    Anna Geller

    Anna Geller

    4 months ago
    Nice work and thanks for the update!