googleapis / googleapis/google-cloud-python

Copying auth.User from MySQL does not work as expected

オープン
#15,940 コメント 2 件 リアクション 0 件 担当者 1 名 @vi3k6i5 が担当を希望しています GitHub で見る
:rotating_light: api: spanner priority: p2 type: bug
主要言語
Python
スター
5.4k
フォーク
1.8k
平均マージ
3日 4時間
マージ済み PR(30日)
122

説明

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.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。