I'm trying to use factory_boy for testing my mongoengine database operations. Here's the mongoengine documents:
import mongoengine
class Address(mongoengine.EmbeddedDocument):
street = mongoengine.StringField()
class Person(mongoengine.Document):
name = mongoengine.StringField()
address = mongoengine.EmbeddedDocumentField(Address)
Then I define the factory classes:
class AddressFactory(factory.mongoengine.MongoEngineFactory):
class Meta:
model = Address
street = factory.Sequence(lambda n: 'street%d' % n)
class PersonFactory(factory.mongoengine.MongoEngineFactory):
class Meta:
model = Person
name = factory.Sequence(lambda n: 'name%d' % n)
address = factory.SubFactory(AddressFactory)
And after I try to use them in test...
import unittest
class TestPerson(unittest.TestCase):
def test_person_creation(self):
person = PersonFactory.create()
assert models.Plan.objects.get(address=plan.address).first()
...and get the following exception which to me looks like if I have not defined the class of the document in meta.model part of my factory class but I did. I guess I'm using the create() method in a wrong way I'm just not sure how.
Traceback (most recent call last):
File "/home/anton/drill_ws/src/drill-hal/tests/test_store.py", line 76, in <module>
person = PersonFactory.create()
File "/home/anton/.local/share/virtualenvs/drill-hal-TAWOMXlQ/lib/python3.7/site-packages/factory/base.py", line 564, in create
return cls._generate(enums.CREATE_STRATEGY, kwargs)
File "/home/anton/.local/share/virtualenvs/drill-hal-TAWOMXlQ/lib/python3.7/site-packages/factory/base.py", line 501, in _generate
return step.build()
File "/home/anton/.local/share/virtualenvs/drill-hal-TAWOMXlQ/lib/python3.7/site-packages/factory/builder.py", line 272, in build
step.resolve(pre)
File "/home/anton/.local/share/virtualenvs/drill-hal-TAWOMXlQ/lib/python3.7/site-packages/factory/builder.py", line 221, in resolve
self.attributes[field_name] = getattr(self.stub, field_name)
File "/home/anton/.local/share/virtualenvs/drill-hal-TAWOMXlQ/lib/python3.7/site-packages/factory/builder.py", line 375, in __getattr__
extra=context,
File "/home/anton/.local/share/virtualenvs/drill-hal-TAWOMXlQ/lib/python3.7/site-packages/factory/declarations.py", line 321, in evaluate
return self.generate(step, defaults)
File "/home/anton/.local/share/virtualenvs/drill-hal-TAWOMXlQ/lib/python3.7/site-packages/factory/declarations.py", line 411, in generate
return step.recurse(subfactory, params, force_sequence=force_sequence)
File "/home/anton/.local/share/virtualenvs/drill-hal-TAWOMXlQ/lib/python3.7/site-packages/factory/builder.py", line 233, in recurse
return builder.build(parent_step=self, force_sequence=force_sequence)
File "/home/anton/.local/share/virtualenvs/drill-hal-TAWOMXlQ/lib/python3.7/site-packages/factory/builder.py", line 272, in build
step.resolve(pre)
File "/home/anton/.local/share/virtualenvs/drill-hal-TAWOMXlQ/lib/python3.7/site-packages/factory/builder.py", line 221, in resolve
self.attributes[field_name] = getattr(self.stub, field_name)
File "/home/anton/.local/share/virtualenvs/drill-hal-TAWOMXlQ/lib/python3.7/site-packages/factory/builder.py", line 375, in __getattr__
extra=context,
File "/home/anton/.local/share/virtualenvs/drill-hal-TAWOMXlQ/lib/python3.7/site-packages/factory/declarations.py", line 321, in evaluate
return self.generate(step, defaults)
File "/home/anton/.local/share/virtualenvs/drill-hal-TAWOMXlQ/lib/python3.7/site-packages/factory/declarations.py", line 411, in generate
return step.recurse(subfactory, params, force_sequence=force_sequence)
File "/home/anton/.local/share/virtualenvs/drill-hal-TAWOMXlQ/lib/python3.7/site-packages/factory/builder.py", line 233, in recurse
return builder.build(parent_step=self, force_sequence=force_sequence)
File "/home/anton/.local/share/virtualenvs/drill-hal-TAWOMXlQ/lib/python3.7/site-packages/factory/builder.py", line 279, in build
kwargs=kwargs,
File "/home/anton/.local/share/virtualenvs/drill-hal-TAWOMXlQ/lib/python3.7/site-packages/factory/base.py", line 315, in instantiate
return self.factory._create(model, *args, **kwargs)
File "/home/anton/.local/share/virtualenvs/drill-hal-TAWOMXlQ/lib/python3.7/site-packages/factory/mongoengine.py", line 26, in _create
instance = model_class(*args, **kwargs)
TypeError: 'NoneType' object is not callable
Related
I have this issue when I try to run upgrade on a migration that will change the type of a VARCHAR column to INTEGER and change the PK too. This is traceback:
The definition of the class is the follow:
class ActionsIntiza(Base):
__tablename__ = 'actions_intiza'
customer_user_id = sa.Column(sa.VARCHAR(20), nullable=False)
customer_id = sa.Column(sa.INTEGER(), primary_key=True, info={'sortkey': True})
intiza_action_created = sa.Column(sa.DATE(), nullable=False)
intiza_action = sa.Column(sa.VARCHAR(50), nullable=False)
intiza_action_type = sa.Column(sa.VARCHAR(50))
intiza_action_tag = sa.Column(sa.VARCHAR(50))
intiza_action_comment = sa.Column(sa.VARCHAR())
intiza_action_attachment = sa.Column(sa.VARCHAR(50))
moni_user_name = sa.Column(sa.VARCHAR(50))
The traceback:
Traceback (most recent call last):
File "C:\Users\Usuario\AppData\Roaming\Python\Python38\site-packages\sqlalchemy\sql\visitors.py", line 88, in _compiler_dispatch
meth = getter(visitor)
AttributeError: 'RedshiftDDLCompiler' object has no attribute 'visit_clause'
op.alter_column('actions_intiza', 'customer_id',
File "<string>", line 8, in alter_column
File "<string>", line 3, in alter_column
File "c:\users\usuario\appdata\local\programs\python\python38\lib\site-packages\alembic\operations\ops.py", line 1777, in alter_column
return operations.invoke(alt)
File "c:\users\usuario\appdata\local\programs\python\python38\lib\site-packages\alembic\operations\base.py", line 345, in invoke
return fn(self, operation)
File "c:\users\usuario\appdata\local\programs\python\python38\lib\site-packages\alembic\operations\toimpl.py", line 43, in alter_column
operations.impl.alter_column(
File "c:\users\usuario\appdata\local\programs\python\python38\lib\site-packages\alembic\ddl\postgresql.py", line 116, in alter_column
self._exec(
File "c:\users\usuario\appdata\local\programs\python\python38\lib\site-packages\alembic\ddl\impl.py", line 134, in _exec
return conn.execute(construct, *multiparams, **params)
File "C:\Users\Usuario\AppData\Roaming\Python\Python38\site-packages\sqlalchemy\engine\base.py", line 982, in execute
return meth(self, multiparams, params)
File "C:\Users\Usuario\AppData\Roaming\Python\Python38\site-packages\sqlalchemy\sql\ddl.py", line 72, in _execute_on_connection
return connection._execute_ddl(self, multiparams, params)
File "C:\Users\Usuario\AppData\Roaming\Python\Python38\site-packages\sqlalchemy\engine\base.py", line 1033, in _execute_ddl
compiled = ddl.compile(
File "<string>", line 1, in <lambda>
File "C:\Users\Usuario\AppData\Roaming\Python\Python38\site-packages\sqlalchemy\sql\elements.py", line 468, in compile
return self._compiler(dialect, bind=bind, **kw)
File "C:\Users\Usuario\AppData\Roaming\Python\Python38\site-packages\sqlalchemy\sql\ddl.py", line 29, in _compiler
return dialect.ddl_compiler(dialect, self, **kw)
File "C:\Users\Usuario\AppData\Roaming\Python\Python38\site-packages\sqlalchemy\sql\compiler.py", line 319, in __init__
self.string = self.process(self.statement, **compile_kwargs)
File "C:\Users\Usuario\AppData\Roaming\Python\Python38\site-packages\sqlalchemy\sql\compiler.py", line 350, in process
return obj._compiler_dispatch(self, **kwargs)
File "C:\Users\Usuario\AppData\Roaming\Python\Python38\site-packages\sqlalchemy\ext\compiler.py", line 436, in <lambda>
lambda *arg, **kw: existing(*arg, **kw),
File "C:\Users\Usuario\AppData\Roaming\Python\Python38\site-packages\sqlalchemy\ext\compiler.py", line 478, in __call__
return fn(element, compiler, **kw)
File "C:\Users\Usuario\AppData\Roaming\Python\Python38\site-packages\sqlalchemy\ext\compiler.py", line 425, in _wrap_existing_dispatch
raise exc.CompileError(
sqlalchemy.exc.CompileError: <class 'alembic.ddl.postgresql.PostgresqlColumnType'> construct has no default compilation handler.
Can you help me?
I'm trying to create fake data for my model which is linked to the auth.User. I'm running Python 3.7 with Django 2.1 django-autofixture 0.12.1:
models.py
Class Person(models.Model):
user = models.OneToOneField(User, on_delete=models.SET_NULL, null=True)
about = models.CharField(max_length=200)
autofixtures.py
Class PersonGenerator(AutoFixture):
field_values = {
'user':InstanceGenerator(autofixture=UserFixture(User)),
'about': LoremGenerator(max_length=200)
}
register(Person,PersonGenerator)
Then I run the autofixtures file to register my generator
py manage.py shell
>>> exec(open('myapp/autofixtures.py').read())
>>> exit()
py manage.py loadtestdata myapp.Person:50
I've got the following error message:
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "D:\..\env\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "D:\..\env\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:\..\env\lib\site-packages\django\core\management\base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "D:\..\env\lib\site-packages\django\core\management\base.py", line 353, in execute
output = self.handle(*args, **options)
File "c:\..\local\programs\python\python37-32\Lib\contextlib.py", line 74, in inner
return func(*args, **kwds)
File "D:\..\env\lib\site-packages\autofixture\management\commands\loadtestdata.py", line 225, in handle
autofixture.create(model, count, **kwargs)
File "D:\..\env\lib\site-packages\autofixture\__init__.py", line 136, in create
return autofixture.create(count, **create_kwargs)
File "D:\..\env\lib\site-packages\autofixture\base.py", line 554, in create
instance = self.create_one(commit=commit, **kwargs)
File "D:\..\env\lib\site-packages\autofixture\base.py", line 501, in create_one
self.process_field(instance, field)
File "D:\..\env\lib\site-packages\autofixture\base.py", line 400, in process_field
value = self.get_value(field)
File "D:\..\env\lib\site-packages\autofixture\base.py", line 396, in get_value
value = generator()
File "D:\..\env\lib\site-packages\autofixture\generators.py", line 71, in __call__
return self.get_value()
File "D:\..\env\lib\site-packages\autofixture\generators.py", line 67, in get_value
value = self.generate()
File "D:\..\env\lib\site-packages\autofixture\generators.py", line 535, in generate
return self.autofixture.create()[0]
File "D:\..\env\lib\site-packages\autofixture\base.py", line 554, in create
instance = self.create_one(commit=commit, **kwargs)
File "D:\..\env\lib\site-packages\autofixture\base.py", line 526, in create_one
self.process_m2m(instance, field)
File "D:\..\env\lib\site-packages\autofixture\base.py", line 413, in process_m2m
return self.process_field(instance, field)
File "D:\..\env\lib\site-packages\autofixture\base.py", line 403, in process_field
setattr(instance, field.name, value)
File "D:\..\env\lib\site-packages\django\db\models\fields\related_descriptors.py", line 537, in __set__
% self._get_set_deprecation_msg_params(),
TypeError: Direct assignment to the forward side of a many-to-many set is prohibited. Use groups.set() instead.
How can it be M2M set when my relationship is one-to-one?
So Django 2 does not allow creating foreign key without saving the instance first. I switched to factory boy and use their SubFactory feature for this and it works.
to fix error with many to many fields for django-autofixture in django 2 you can do it like this
class News(models.Model):
categories = models.ManyToManyField(Category, blank=True)
title = models.CharField(max_length=255)
class Category(models.Model):
title = models.CharField(max_length=255)
news = AutoFixture(News).Create(1, commit=False)
news.save()
news.categories.set([AutoFixture(Category).create_one()])
When I am executing celery task it is giving me:
ValueError: Related model u'user.User' cannot be resolved
The stacktrace is
Traceback (most recent call last):
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/celery/app/trace.py", line 375, in trace_task
R = retval = fun(*args, **kwargs)
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/celery/app/trace.py", line 632, in __protected_call__
return self.run(*args, **kwargs)
File "/Users/prince/work/magneto/set/facebook_pages/tasks.py", line 23, in analyze_page
connected_facebook_page = get_connected_facebook_page(connected_facebook_page_id)
File "/Users/prince/work/magneto/set/facebook_pages/utils.py", line 49, in get_connected_facebook_page
return ConnectedUserPage.objects.get(id=connected_facebook_page_id)
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/query.py", line 374, in get
num = len(clone)
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/query.py", line 232, in __len__
self._fetch_all()
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/query.py", line 1118, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/query.py", line 53, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch)
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 876, in execute_sql
sql, params = self.as_sql()
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 428, in as_sql
extra_select, order_by, group_by = self.pre_sql_setup()
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 46, in pre_sql_setup
self.setup_query()
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 37, in setup_query
self.select, self.klass_info, self.annotation_col_map = self.get_select()
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 194, in get_select
for c in self.get_default_columns():
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 569, in get_default_columns
column = field.get_col(alias)
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/fields/related.py", line 1008, in get_col
return super(ForeignKey, self).get_col(alias, output_field or self.target_field)
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/fields/related.py", line 909, in target_field
return self.foreign_related_fields[0]
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/fields/related.py", line 653, in foreign_related_fields
return tuple(rhs_field for lhs_field, rhs_field in self.related_fields if rhs_field)
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/fields/related.py", line 640, in related_fields
self._related_fields = self.resolve_related_fields()
File "/Users/prince/virtualenvs/set/lib/python2.7/site-packages/django/db/models/fields/related.py", line 625, in resolve_related_fields
raise ValueError('Related model %r cannot be resolved' % self.remote_field.model)
ValueError: Related model u'user.User' cannot be resolved
Here ConnectedUserPage is a model with schema:
class ConnectedUserPage(TimeStampedModel):
user = models.ForeignKey('user.User', on_delete=models.PROTECT)
page = models.ForeignKey(FacebookPage, on_delete=models.PROTECT)
page_details = jsonb.JSONField()
My versions are :
celery==4.1.1
django-celery-beat==1.1.1
django-celery-results==1.0.1
Django==1.11.13
In case I directly import User model from user app I am getting stuck in circular imports.
Any help would be appreciated, stuck in this loop for a quite while now.
Where's User defined? Is this Django's own user model? If that's the case you can use User model directly:
from django.contrib.auth import get_user_model
User = get_user_model()
class ConnectedUserPage(TimeStampedModel):
user = models.ForeignKey(User, unique=True)
or you can also do
from django.conf import settings
class ConnectedUserPage(TimeStampedModel):
user = models.ForeignKey(settings.AUTH_USER_MODEL)
If it is your own supplied User model, are you sure user is in INSTALLED_APPS?
I'm writing unit tests for my Django REST Framework app and I'm creating my fake testing data using factory_boy. I've come across the following error message when I try to run my tests
File "/Users/thomasheatwole/osf-meetings/meetings/conferences/tests.py", line 69, in setUp
contributor = UserFactory()
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/factory/base.py", line 67, in __call__
return cls.create(**kwargs)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/factory/base.py", line 594, in create
return cls._generate(True, attrs)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/factory/base.py", line 519, in _generate
obj = cls._prepare(create, **attrs)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/factory/base.py", line 494, in _prepare
return cls._create(model_class, *args, **kwargs)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/factory/django.py", line 181, in _create
return manager.create(*args, **kwargs)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/db/models/manager.py", line 122, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/db/models/query.py", line 401, in create
obj.save(force_insert=True, using=self.db)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/db/models/base.py", line 708, in save
force_update=force_update, update_fields=update_fields)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/db/models/base.py", line 745, in save_base
update_fields=update_fields, raw=raw, using=using)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 192, in send
response = receiver(signal=self, sender=sender, **named)
File "/Users/thomasheatwole/osf-meetings/meetings/submissions/signals.py", line 19, in add_permissions_on_submission_save
submission, submission_contributor, conference_admin, approval)
File "/Users/thomasheatwole/osf-meetings/meetings/submissions/permissions.py", line 167, in set_unapproved_submission_permissions
approval, submission_contributor)
File "/Users/thomasheatwole/osf-meetings/meetings/approvals/permissions.py", line 62, in add_approval_permissions_to_submission_contributor
assign_perm("approvals.delete_approval", submission_contributor, approval)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/guardian/shortcuts.py", line 92, in assign_perm
return model.objects.assign_perm(perm, user, obj)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/guardian/managers.py", line 43, in assign_perm
obj_perm, created = self.get_or_create(**kwargs)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/db/models/manager.py", line 122, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/db/models/query.py", line 467, in get_or_create
return self._create_object_from_params(lookup, params)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/db/models/query.py", line 499, in _create_object_from_params
obj = self.create(**params)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/db/models/query.py", line 401, in create
obj.save(force_insert=True, using=self.db)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/guardian/models.py", line 39, in save
content_type = ContentType.objects.get_for_model(self.content_object)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/contrib/contenttypes/models.py", line 55, in get_for_model
opts = self._get_opts(model, for_concrete_model)
File "/Users/thomasheatwole/.virtualenvs/django/lib/python2.7/site-packages/django/contrib/contenttypes/models.py", line 32, in _get_opts
model = model._meta.concrete_model
AttributeError: 'NoneType' object has no attribute '_meta'
I pretty much have no clue what's going on since my understanding of backend structure isn't great. Here's the factories:
class UserFactory(factory.DjangoModelFactory):
class Meta:
model = User
class ConferenceFactory(factory.DjangoModelFactory):
class Meta:
model = Conference
class ApprovalFactory(factory.DjangoModelFactory):
class Meta:
model = approvalModels.Approval
class SubmissionFactory(factory.DjangoModelFactory):
class Meta:
model = submissionModels.Submission
And here's where I call them:
def setUp(self):
self.user1 = UserFactory(
username = 'Leo',
id = '99'
)
self.user2 = UserFactory(
username = 'LeoLeo'
)
self.conference = ConferenceFactory(
admin = self.user1
)
self.submission1 = SubmissionFactory(
conference = self.conference,
contributor = UserFactory()
)
self.submission2 = SubmissionFactory(
conference = self.conference,
contributor = UserFactory()
)
If you look through the error message, it's specifically complaining about contributor = UserFactory()
Let me know if there's an easy fix, or even some explanation of what's going on would be nice.
Thanks so much!
Here's the file:
tests.py
You need to add correct relations (SubFactory) in the factory definition first.
Please read this part carefully:
http://factoryboy.readthedocs.io/en/latest/recipes.html#copying-fields-to-a-subfactory
I'm trying to create following self-referencing EndpointsModel (the trick with _fix_up_properties() is taken from here: https://groups.google.com/forum/#!topic/appengine-ndb-discuss/1FmgEVK7JNM):
class EventFieldSchema(EndpointsModel):
name = ndb.StringProperty(required=True)
type = msgprop.EnumProperty(EventType, required=True)
EventFieldSchema.nested_fields = ndb.LocalStructuredProperty(EventFieldSchema,repeated=True)
EventFieldSchema._fix_up_properties()
This works for datastore model, but unfortunately, the nested_fields field won't be included into ProtoRPC message.
I've tried to manually specify message fields schema, by adding at the end following line:
EventFieldSchema._message_fields_schema = ('name', 'type', 'nested_fields')
but then app-engine fails, going into a loop, trying turn EventFieldSchema into ProtoRPC field:
Traceback (most recent call last):
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/base/data/home/apps/s~project/eventregistry:dev.380885914276541023/main.py", line 3, in <module>
from er.api.event import EventRegistryApi
File "/base/data/home/apps/s~project/eventregistry:dev.380885914276541023/er/api/event.py", line 17, in <module>
class EventRegistryApi(remote.Service):
File "/base/data/home/apps/s~project/eventregistry:dev.380885914276541023/er/api/event.py", line 23, in EventRegistryApi
name='%s.insert' % RESOURCE_NAME)
File "/base/data/home/runtimes/python27/python27_lib/versions/third_party/protorpc-1.0/protorpc/util.py", line 170, in positional_wrapper
return wrapped(*args, **kwargs)
File "/base/data/home/apps/s~project/eventregistry:dev.380885914276541023/endpoints_proto_datastore/ndb/model.py", line 1359, in method
kwargs[REQUEST_MESSAGE] = cls.ProtoModel(fields=request_fields)
File "/base/data/home/apps/s~project/eventregistry:dev.380885914276541023/endpoints_proto_datastore/ndb/model.py", line 1031, in ProtoModel
allow_message_fields=allow_message_fields)
File "/base/data/home/apps/s~project/eventregistry:dev.380885914276541023/endpoints_proto_datastore/ndb/model.py", line 969, in _MessageFields
proto_attr = to_proto(prop, field_index)
File "/base/data/home/apps/s~project/eventregistry:dev.380885914276541023/endpoints_proto_datastore/ndb/utils.py", line 137, in StructuredPropertyToProto
property_proto = property_proto_method()
File "/base/data/home/apps/s~project/eventregistry:dev.380885914276541023/endpoints_proto_datastore/ndb/model.py", line 1031, in ProtoModel
allow_message_fields=allow_message_fields)
File "/base/data/home/apps/s~project/eventregistry:dev.380885914276541023/endpoints_proto_datastore/ndb/model.py", line 969, in _MessageFields
proto_attr = to_proto(prop, field_index)
File "/base/data/home/apps/s~project/eventregistry:dev.380885914276541023/endpoints_proto_datastore/ndb/utils.py", line 137, in StructuredPropertyToProto
property_proto = property_proto_method()
File "/base/data/home/apps/s~project/eventregistry:dev.380885914276541023/endpoints_proto_datastore/ndb/model.py", line 1031, in ProtoModel
Is this a bug in EndpointsModel? What is the "proper" way of defining self-referencing EndpointsModels?
Having the same issue with self-referencing an EndpointsModel:
class UnitsProtoModel(EndpointsModel):
""" ProtoRPC Model for storing/retrieving a unit. """
_message_fields_schema = ('id', 'uic', 'parent_id', 'branch_id', 'name')
uic = ndb.StringProperty(required=True)
parent_id = ndb.StringProperty(required=True, default=None)
branch_id = ndb.StringProperty(required=True)
name = ndb.StringProperty(required=True)
abbreviated_name = ndb.StringProperty(default="")
flagged = ndb.BooleanProperty(default=False)
message = ndb.StringProperty(default="")
unit_created_at = ndb.DateTimeProperty(auto_now_add=True)
class UnitsCollection(EndpointsModel):
items = messages.MessageField(UnitsProtoModel, 1, repeated=True)
Error msg:
`File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine- default.bundle/Contents/Resources/google_appengine/lib/protorpc-1.0/protorpc/util.py", line 170, in positional_wrapper
return wrapped(*args, **kwargs)
File "/Applications/GoogleAppEngineLauncher.app/Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib/protorpc-1.0/protorpc/messages.py", line 1531, in init
raise FieldDefinitionError('Invalid message class: %s' % message_type)
FieldDefinitionError: Invalid message class:
UnitsProtoModel<abbreviated_name=StringProperty('abbreviated_name', default=''), branch_id=StringProperty('branch_id', required=True), flagged=BooleanProperty('flagged', default=False), message=StringProperty('message', default=''), name=StringProperty('name', required=True), owner=UserProperty('owner'), parent_id=StringProperty('parent_id', required=True), uic=StringProperty('uic', required=True), unit_created_at=DateTimeProperty('unit_created_at', auto_now_add=True)>`