Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Tuples in cursor.excecutemany does not work with aurora_data_api.connect() #45

Closed
yuvaljacob opened this issue Feb 9, 2022 · 6 comments

Comments

@yuvaljacob
Copy link

I have noticed that when using the aurora_data_api, when using the cursor.executemany method for a MySQL DB, I cannot use a list of Tuples, only a list of dicts is processed correctly, while the "official" MySQL Python docs give an example of using a Tuple and not a dict.

When I try to use a list of Tuples with cursor.excecutemany, like seen below, I get an error message regarding Tuples:

            INSERT INTO aurora_data_api_test
            (name, doc, num, ts)
            VALUES (%s, %s, %s, %s)
            """
            
            data = [(f"name-{i}", f"doc-{i}", "5.0", "2020-09-17 13:49:32.780180") for i in range(2048)]
            
            response = cursor.executemany(sql, data)

[ERROR] AttributeError: 'tuple' object has no attribute 'items'

I believe that it is related to this part in your init.py file, which expects to get a dict:

def _format_parameter_set(self, parameters):
      return [self.prepare_param(k, v) for k, v in parameters.items()]

Can you please help me with understanding this gap? The only way that it seems to work with auroro_data_api, is if I do this instead:

sql = """
            INSERT INTO aurora_data_api_test
            (name, doc, num, ts)
            VALUES (:name, :doc, :num, :ts)
            """

            response = cursor.executemany(sql, [
                {
                    "name": f"name-{i}",
                    "doc": f"doc-{i}",
                    "num": "5.0",
                    "ts": "2020-09-17 13:49:32.780180"
                } for i in range(2048)]
            )

If I run the code above and use my local docker image with the latest MySQL image, I get this error:

pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':name, :doc, :num, :ts)' at line 3")

@yuvaljacob yuvaljacob changed the title Using Tuples in cursor.excecutemany does not work with the aurora_data_api.connect() Using Tuples in cursor.excecutemany does not work with aurora_data_api.connect() Feb 10, 2022
@kislyuk
Copy link
Contributor

kislyuk commented Feb 21, 2022

Thanks for reporting - this is just to acknowledge that this seems like an issue in the mysql implementation. I'll take a look when I get a chance to spin up a test RDS instance again.

@yuvaljacob

This comment was marked as off-topic.

@kislyuk

This comment was marked as off-topic.

@yuvaljacob

This comment was marked as off-topic.

@kislyuk

This comment was marked as off-topic.

@kislyuk
Copy link
Contributor

kislyuk commented Feb 25, 2022

RDS Data API does not support array parameters. Added an error message to make this explicit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants