googleapis / googleapis/google-cloud-python

Copying auth.User from MySQL does not work as expected

未关闭
#15,940 2 条评论 0 个 reaction 已指派 1 人 已被 @vi3k6i5 认领 在 GitHub 查看
:rotating_light: api: spanner priority: p2 type: bug
主要语言
Python
星标
5.4k
派生
1.8k
平均合并
3 天 4 小时
30 天内合并 PR
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 摘要。