Skip to content

bug: createNewUserIfNotExists fails twice on custom project #1580

@phorward

Description

@phorward

I have a ViUR project which has customization to the UserSkel. It directly raises exceptions when trying to setup a default user.

First bug, because status was overwritten with a project-defined enum:

[2025-09-27 23:07:49,153] /.../core/modules/user.py:1777 [CRITICAL] Something went wrong when trying to add admin user 'admin@bidetec-viur3.appspot.com' with Password 'DerkPAUAz85tt'
[2025-09-27 23:07:49,153] /.../core/modules/user.py:1778 [ERROR] ('Unknown protobuf attr type', <enum 'Status'>)
Traceback (most recent call last):
  File "~/myproject/.venv/lib/python3.13/site-packages/viur/core/modules/user.py", line 1775, in createNewUserIfNotExists
    addSkel.write()
    ~~~~~~~~~~~~~^^
  File "~/myproject/deploy/skeletons/user.py", line 372, in write
    return super().write(skel, **kwargs)
           ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "~/myproject/deploy/bidetec/skeletons/user.py", line 336, in write
    return super().write(skel=skel, key=key, update_relations=update_relations, _check_legacy=_check_legacy)
           ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/myproject/.venv/lib/python3.13/site-packages/viur/core/modules/user.py", line 182, in write
    return super().write(skel, *args, **kwargs)
           ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "~/myproject/.venv/lib/python3.13/site-packages/viur/core/skeleton/skeleton.py", line 597, in write
    key, skel, change_list, is_add = db.run_in_transaction(__txn_write, skel)
                                     ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "~/myproject/.venv/lib/python3.13/site-packages/viur/core/db/transport.py", line 123, in run_in_transaction
    res = func(*args, **kwargs)
  File "~/myproject/.venv/lib/python3.13/site-packages/viur/core/skeleton/skeleton.py", line 547, in __txn_write
    db.put(skel.dbEntity)
    ~~~~~~^^^^^^^^^^^^^^^
  File "~/myproject/.venv/lib/python3.13/site-packages/viur/core/db/transport.py", line 70, in put
    return __client__.put(entities)
           ~~~~~~~~~~~~~~^^^^^^^^^^
  File "~/myproject/.venv/lib/python3.13/site-packages/google/cloud/datastore/client.py", line 627, in put
    self.put_multi(entities=[entity], retry=retry, timeout=timeout)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/myproject/.venv/lib/python3.13/site-packages/google/cloud/datastore/client.py", line 664, in put_multi
    current.put(entity)
    ~~~~~~~~~~~^^^^^^^^
  File "~/myproject/.venv/lib/python3.13/site-packages/google/cloud/datastore/transaction.py", line 360, in put
    super(Transaction, self).put(entity)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
  File "~/myproject/.venv/lib/python3.13/site-packages/google/cloud/datastore/batch.py", line 252, in put
    _assign_entity_to_pb(entity_pb, entity)
    ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "~/myproject/.venv/lib/python3.13/site-packages/google/cloud/datastore/batch.py", line 407, in _assign_entity_to_pb
    bare_entity_pb = helpers.entity_to_protobuf(entity)
  File "~/myproject/.venv/lib/python3.13/site-packages/google/cloud/datastore/helpers.py", line 226, in entity_to_protobuf
    _set_protobuf_value(value_pb, value)
    ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "~/myproject/.venv/lib/python3.13/site-packages/google/cloud/datastore/helpers.py", line 504, in _set_protobuf_value
    attr, val = _pb_attr_value(val)
                ~~~~~~~~~~~~~~^^^^^
  File "~/myproject/.venv/lib/python3.13/site-packages/google/cloud/datastore/helpers.py", line 418, in _pb_attr_value
    raise ValueError("Unknown protobuf attr type", type(val))
ValueError: ('Unknown protobuf attr type', <enum 'Status'>)

When fixing this bug, the next bug occurs, because a non-required FileBone for a profile picture exists in the UserSkel...

[2025-09-27 23:10:22,747] /.../core/modules/user.py:1777 [CRITICAL] Something went wrong when trying to add admin user 'admin@bidetec-viur3.appspot.com' with Password 'iQSWJGGHgZLPa'
[2025-09-27 23:10:22,747] /.../core/modules/user.py:1778 [ERROR] 'NoneType' object has no attribute 'is_deferred'
Traceback (most recent call last):
  File "~/myproject/.venv/lib/python3.13/site-packages/viur/core/modules/user.py", line 1775, in createNewUserIfNotExists
    addSkel.write()
    ~~~~~~~~~~~~~^^
  File "~/myproject/deploy/skeletons/user.py", line 372, in write
    return super().write(skel, **kwargs)
           ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
  File "~/myproject/deploy/bidetec/skeletons/user.py", line 336, in write
    return super().write(skel=skel, key=key, update_relations=update_relations, _check_legacy=_check_legacy)
           ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "~/myproject/.venv/lib/python3.13/site-packages/viur/core/modules/user.py", line 182, in write
    return super().write(skel, *args, **kwargs)
           ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "~/myproject/.venv/lib/python3.13/site-packages/viur/core/skeleton/skeleton.py", line 600, in write
    bone.postSavedHandler(skel, bone_name, key)
    ~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "~/myproject/.venv/lib/python3.13/site-packages/viur/core/bones/file.py", line 250, in postSavedHandler
    current.request.get().is_deferred
AttributeError: 'NoneType' object has no attribute 'is_deferred'

Metadata

Metadata

Assignees

No one assigned

    Labels

    annoyingbug(fix)Something isn't working or address a specific issue or vulnerability

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions