googleapis / googleapis/google-cloud-python

Copying auth.User from MySQL does not work as expected

Ouverte
#15,940 2 commentaires 0 réactions 1 personne assignée Réclamée par @vi3k6i5 Voir sur GitHub
:rotating_light: api: spanner priority: p2 type: bug
Langage dominant
Python
Étoiles
5.4k
Forks
1.8k
Merge moyen
3 j 4 h
PR mergées (30 j)
122

Description

Using 2.2.24 with default pointing to MySQL and "spanner" pointing to new spanner instance

```
In [32]: u = User.objects.first()

In [33]: u.save(using="spanner")
/repose-cache/py/env/lib/python3.7/site-packages/django/db/backends/utils.py:23: UserWarning: The `rowcount` property is non-operational. Request resulting rows are streamed by the `fetch*()` methods and can't be counted before they are all streamed.
cursor_attr = getattr(self.cursor, attr)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
in
----> 1 u.save(using="spanner")

/repose-cache/py/env/lib/python3.7/site-packages/django/contrib/auth/base_user.py in save(self, *args, **kwargs)
64
65 def save(self, *args, **kwargs):
---> 66 super().save(*args, **kwargs)
67 if self._password is not None:
68 password_validation.password_changed(self._password, self)

/repose-cache/py/env/lib/python3.7/site-packages/django/db/models/base.py in save(self, force_insert, force_update, using, update_fields)
742
743 self.save_base(using=using, force_insert=force_insert,
--> 744 force_update=force_update, update_fields=update_fields)
745 save.alters_data = True
746

/repose-cache/py/env/lib/python3.7/site-packages/django/db/models/base.py in save_base(self, raw, force_insert, force_update, using, update_fields)
780 updated = self._save_table(
781 raw, cls, force_insert or parent_inserted,
--> 782 force_update, using, update_fields,
783 )
784 # Store the database on which the object was saved

/repose-cache/py/env/lib/python3.7/site-packages/django/db/models/base.py in _save_table(self, raw, cls, force_insert, force_update, using, update_fields)
852 forced_update = update_fields or force_update
853 updated = self._do_update(base_qs, using, pk_val, values, update_fields,
--> 854 forced_update)
855 if force_update and not updated:
856 raise DatabaseError("Forced update did not affect any rows.")

/repose-cache/py/env/lib/python3.7/site-packages/django/db/models/base.py in _do_update(self, base_qs, using, pk_val, values, update_fields, forced_update)
901 (filtered._update(values) > 0 or filtered.exists())
902 )
--> 903 return filtered._update(values) > 0
904
905 def _do_insert(self, manager, using, fields, update_pk, raw):

TypeError: '>' not supported between instances of 'NoneType' and 'int'
```

As an experimental hack, I changed line 903 in django/db/models/base.py to `return (filtered._update(values) or 0) > 0`. https://github.com/django/django/compare/2.2.25...skyl:spanner-exp?expand=1

That actually "worked" in that I was able to save the user to spanner. But, I wonder if this could be prevented/fixed in `django_spanner` library.

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.