(self, response)
| 296 | return response |
| 297 | |
| 298 | async def response_handler(self, response): |
| 299 | m2m_selects = [ |
| 300 | i |
| 301 | for i in self.columns_delegate.selected_columns |
| 302 | if isinstance(i, M2MSelect) |
| 303 | ] |
| 304 | for m2m_select in m2m_selects: |
| 305 | m2m_name = m2m_select.m2m._meta.name |
| 306 | secondary_table = m2m_select.m2m._meta.secondary_table |
| 307 | secondary_table_pk = secondary_table._meta.primary_key |
| 308 | |
| 309 | if self.engine_type == "sqlite": |
| 310 | # With M2M queries in SQLite, we always get the value back as a |
| 311 | # list of strings, so we need to do some type conversion. |
| 312 | value_type = ( |
| 313 | m2m_select.columns[0].__class__.value_type |
| 314 | if m2m_select.as_list and m2m_select.serialisation_safe |
| 315 | else secondary_table_pk.value_type |
| 316 | ) |
| 317 | try: |
| 318 | for row in response: |
| 319 | data = row[m2m_name] |
| 320 | row[m2m_name] = ( |
| 321 | [value_type(i) for i in row[m2m_name]] |
| 322 | if data |
| 323 | else [] |
| 324 | ) |
| 325 | except ValueError: |
| 326 | colored_warning( |
| 327 | "Unable to do type conversion for the " |
| 328 | f"{m2m_name} relation" |
| 329 | ) |
| 330 | |
| 331 | # If the user requested a single column, we just return that |
| 332 | # from the database. Otherwise we request the primary key |
| 333 | # value, so we can fetch the rest of the data in a subsequent |
| 334 | # SQL query - see below. |
| 335 | if m2m_select.as_list: |
| 336 | if m2m_select.serialisation_safe: |
| 337 | pass |
| 338 | else: |
| 339 | response = await self._splice_m2m_rows( |
| 340 | response, |
| 341 | secondary_table, |
| 342 | secondary_table_pk, |
| 343 | m2m_name, |
| 344 | m2m_select, |
| 345 | as_list=True, |
| 346 | ) |
| 347 | else: |
| 348 | if ( |
| 349 | len(m2m_select.columns) == 1 |
| 350 | and m2m_select.serialisation_safe |
| 351 | ): |
| 352 | column_name = m2m_select.columns[0]._meta.name |
| 353 | for row in response: |
| 354 | row[m2m_name] = [ |
| 355 | {column_name: i} for i in row[m2m_name] |
nothing calls this directly
no test coverage detected