Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copying auth.User from MySQL does not work as expected #744

Open
skyl opened this issue Dec 20, 2021 · 1 comment
Open

Copying auth.User from MySQL does not work as expected #744

skyl opened this issue Dec 20, 2021 · 1 comment
Assignees
Labels
api: spanner Issues related to the googleapis/python-spanner-django API. priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@skyl
Copy link

skyl commented Dec 20, 2021

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)
<ipython-input-33-045c9fec6642> in <module>
----> 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.

@skyl skyl added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Dec 20, 2021
@product-auto-label product-auto-label bot added the api: spanner Issues related to the googleapis/python-spanner-django API. label Dec 20, 2021
@vi3k6i5
Copy link
Contributor

vi3k6i5 commented Dec 21, 2021

Thanks for brining this to our notice, I am looking into this. Will try difference database timeout options first and then investigate the right way to reuse connections from connection pool.

@yoshi-automation yoshi-automation added 🚨 This issue needs some love. and removed 🚨 This issue needs some love. labels Mar 21, 2022
@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Jun 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the googleapis/python-spanner-django API. priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

3 participants