ramses-tech / ramses

RAML + Elasticsearch / Postgres / Mongodb / Your Data Store™ + Pyramid = RESTful API
http://ramses.tech
Apache License 2.0
303 stars 29 forks source link

RAML declaration order and Model relationships #88

Closed adam-codeberg closed 8 years ago

adam-codeberg commented 9 years ago

If a Parent model is before a Child model in the RAML the Child model is not created at the time the Parent looks for it.

Example see /contacts and /emails here /addressbook/api.raml

As a work around, the issue does not occur when the Parent is placed after the Child, however this prohibits the ability to nest objects for a more intuitive API structure.

This error is produced

Starting subprocess with file monitor
2015-10-10 16:04:28,697 INFO  [nefertari_sqla.signals][MainThread] signals.setup_es_signals_for: setup_sqla_es_signals_for: <class 'nefertari_sqla.documents.ESBaseDocument'>
2015-10-10 16:04:28,700 INFO  [nefertari][MainThread] __init__.includeme: nefertari 0.6.0
2015-10-10 16:04:28,703 INFO  [nefertari.json_httpexceptions][MainThread] json_httpexceptions.includeme: Include json_httpexceptions
2015-10-10 16:04:28,703 INFO  [ramses][MainThread] __init__.includeme: Parsing RAML
2015-10-10 16:04:28,800 INFO  [ramses][MainThread] __init__.includeme: Starting models generation
2015-10-10 16:04:28,801 INFO  [ramses.generators][MainThread] generators.generate_models: Configuring model for route `contacts`
2015-10-10 16:04:28,806 DEBUG [ramses.models][MainThread] models.get_existing_model: Model `Contact` does not exist
2015-10-10 16:04:28,806 INFO  [ramses.utils][MainThread] utils.resource_schema: Searching for model schema
2015-10-10 16:04:28,806 INFO  [ramses.models][MainThread] models.setup_data_model: Generating model class `Contact`
2015-10-10 16:04:28,808 DEBUG [ramses.models][MainThread] models.get_existing_model: Model `Phone` does not exist
Traceback (most recent call last):
  File "/removed-base-directory/bin/pserve", line 11, in <module>
    sys.exit(main())
  File "/removed-base-directory/lib/python2.7/site-packages/pyramid/scripts/pserve.py", line 58, in main
    return command.run()
  File "/removed-base-directory/lib/python2.7/site-packages/pyramid/scripts/pserve.py", line 328, in run
    global_conf=vars)
  File "/removed-base-directory/lib/python2.7/site-packages/pyramid/scripts/pserve.py", line 363, in loadapp
    return loadapp(app_spec, name=name, relative_to=relative_to, **kw)
  File "/removed-base-directory/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 247, in loadapp
    return loadobj(APP, uri, name=name, **kw)
  File "/removed-base-directory/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 272, in loadobj
    return context.create()
  File "/removed-base-directory/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 710, in create
    return self.object_type.invoke(self)
  File "/removed-base-directory/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 144, in invoke
    **context.local_conf)
  File "/removed-base-directory/lib/python2.7/site-packages/paste/deploy/util.py", line 55, in fix_call
    val = callable(*args, **kw)
  File "/removed-base-directory/lib/python2.7/site-packages/paste/urlmap.py", line 31, in urlmap_factory
    app = loader.get_app(app_name, global_conf=global_conf)
  File "/removed-base-directory/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 350, in get_app
    name=name, global_conf=global_conf).create()
  File "/removed-base-directory/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 710, in create
    return self.object_type.invoke(self)
  File "/removed-base-directory/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 146, in invoke
    return fix_call(context.object, context.global_conf, **context.local_conf)
  File "/removed-base-directory/lib/python2.7/site-packages/paste/deploy/util.py", line 55, in fix_call
    val = callable(*args, **kw)
  File "/removed-base-directory/addressbook-api/addressbook/__init__.py", line 9, in main
    config.include('ramses')
  File "/removed-base-directory/lib/python2.7/site-packages/pyramid/config/__init__.py", line 755, in include
    c(configurator)
  File "/removed-base-directory/lib/python2.7/site-packages/ramses/__init__.py", line 48, in includeme
    generate_models(config, raml_resources=raml_root.resources)
  File "/removed-base-directory/lib/python2.7/site-packages/ramses/generators.py", line 178, in generate_models
    config, raml_resource, route_name)
  File "/removed-base-directory/lib/python2.7/site-packages/ramses/models.py", line 209, in handle_model_generation
    raise ValueError('{}: {}'.format(model_name, str(ex)))
ValueError: Contact: Model `Phone` used in relationship `phone_numbers` is not defined
adam-codeberg commented 9 years ago

Issue may be due to using underscores in JSON relationship declerations.

Example /addressbook/schemas/contacts.json Changed phone_number to phone and the issue goes away.

adam-codeberg commented 9 years ago

The workaround works, but not sure if this is symptomatic of a deeper issue.

Have checked pypi and all packages are up to date and incorporated the setup.py provided on git into the project, however issue persists.

jstoiko commented 9 years ago

Thanks for reporting this @adam-codeberg, was able to reproduce. This is a bug.

adam-codeberg commented 9 years ago

Thanks for looking into it.