| 3502 | |
| 3503 | @event.listens_for(connection, "before_cursor_execute", retval=True) |
| 3504 | def revert_insert( |
| 3505 | conn, cursor, statement, parameters, context, executemany |
| 3506 | ): |
| 3507 | if re.match(r"INSERT.* RETURNING (?:my_table.)?id", statement): |
| 3508 | if executemany and isinstance(parameters, list): |
| 3509 | # remove some rows, so the count is wrong |
| 3510 | parameters = parameters[0:1] |
| 3511 | else: |
| 3512 | # statement should return no rows |
| 3513 | statement = ( |
| 3514 | "UPDATE my_table SET id=NULL WHERE 1!=1 " |
| 3515 | "RETURNING my_table.id" |
| 3516 | ) |
| 3517 | parameters = {} |
| 3518 | else: |
| 3519 | assert not testing.against( |
| 3520 | "postgresql" |
| 3521 | ), "this test has to at least run on PostgreSQL" |
| 3522 | testing.config.skip_test( |
| 3523 | "backend doesn't support the expected form of " |
| 3524 | "RETURNING for this test to work" |
| 3525 | ) |
| 3526 | |
| 3527 | return statement, parameters |
| 3528 | |
| 3529 | return MyClass |
| 3530 | |