-
Notifications
You must be signed in to change notification settings - Fork 49
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
Polymodel instances' class_
attribute should contain a list of str
objects on creation
#89
Comments
AFAICS, Cloud NDB always uses |
spiqueras
pushed a commit
to spiqueras/appengine-python-standard
that referenced
this issue
Jun 29, 2023
1 task
We are considering this change. It will take some time because we need to ensure this will not break existing users. |
This was added as part providing py2->py3 support. b/139757579 cl/276076727
…On Tue, Jul 25, 2023 at 11:21 AM shreejad ***@***.***> wrote:
We are considering this change. It will take some time because we need to
ensure this will not break existing users.
My current plan is to introduce this change in the next Major Version
update enabled by a flag. In a subsequent update, we can update the flag to
be enabled by default.
—
Reply to this email directly, view it on GitHub
<#89 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADUIHGYM6WNPGXRPNJIFQELXSAFELANCNFSM6AAAAAAYQMTV7A>
.
You are receiving this because you are subscribed to this thread.Message
ID: <GoogleCloudPlatform/appengine-python-standard/issues/89/1650323661@
github.com>
|
spiqueras
pushed a commit
to spiqueras/appengine-python-standard
that referenced
this issue
Aug 7, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expected Behavior
Polyclass models have a read-only attribute called
class_
that contains the class hierarchy in form of a list. This attribute should always contain a list of eitherstr
orbytes
, preferably the former.Actual Behavior
On instance creation, the
class_
attribute is filled withbytes
objects. After the object is put and on any subsequent read, this attribute will containstr
objects instead. This makes the attribute hard to rely on, as if you ever want to use it you need to know if the entity has already been written to the database or not or convert between types. It also breaks instance equality checks when one of the instance has just been created and the other has been retrieved from the database.This is similar in Python 2 SDK (the attribute is of type
str
pre-put
andunicode
after), but due to Python 2'sstr
andunicode
being mostly compatible, it wasn't that much of an issue.Steps to Reproduce the Problem
The following test will work fine in Python 2 but fail in Python 3.
The error
FAILED tests_py3/model_test.py::test_class_in_polymodel - AssertionError: assert APolymodel(key=Key('APolymodel', 1), class_=['APolymodel']) == APolymodel(key=Key('APolymodel', 1), class_=[b'APolymodel'])
The offending code is likely the following:
appengine-python-standard/src/google/appengine/ext/ndb/polymodel.py
Lines 214 to 219 in ad6e5cc
Unless there's a clear reason to enforce
class_
being abytes
list on instance creation, I'd be great to remove theensure_binary
, making it consistently anstr
list.Goes without saying, but this issue does not happen to classes that inherit from
ndb.Model
.Specifications
The text was updated successfully, but these errors were encountered: