GithubHelp home page GithubHelp logo

jazzband / django-ddp Goto Github PK

View Code? Open in Web Editor NEW
167.0 167.0 29.0 548 KB

Django/PostgreSQL implementation of the Meteor server.

License: MIT License

Python 97.23% CSS 0.99% HTML 0.16% JavaScript 0.36% Shell 0.35% Makefile 0.92%

django-ddp's People

Contributors

janusle avatar legostormtroopr avatar schinckel avatar tysonclugg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-ddp's Issues

Support raw websocket connections

django-ddp always responds with SockJS-style framing, regardless of the URL used to connect to the websocket

For example: a["{\"server_id\":\"0\"}"]

Using /websocket and /sockjs/websocket should return raw, unframed data while /sockjs/999/foo/websocket should use the SockJS framing.

Python3 compatibility error

I don't know how to fix this in a python2 and python3 compatible way sorry. Your pypy entry does suggest python3 is supported https://pypi.python.org/pypi/django-ddp/0.19.1

I had to make this change for python3.5

--- a/dddp/views.py
+++ b/dddp/views.py
@@ -26,7 +26,7 @@ def dict_merge(lft, rgt):
if not isinstance(rgt, dict):
return rgt
result = deepcopy(lft)

  • for key, val in rgt.iteritems():
  • for key, val in rgt.items():
    if key in result and isinstance(result[key], dict):
    result[key] = dict_merge(result[key], val)
    else:

Getting The following error

Traceback (most recent call last):
File "/var/www/html/py35_ev/lib/python3.5/site-packages/gevent/pywsgi.py", line 936, in handle_one_response
self.run_application()
File "/var/www/html/py35_ev/lib/python3.5/site-packages/geventwebsocket/handler.py", line 88, in run_application
return super(WebSocketHandler, self).run_application()
File "/var/www/html/py35_ev/lib/python3.5/site-packages/gevent/pywsgi.py", line 910, in run_application
self.process_result()
File "/var/www/html/py35_ev/lib/python3.5/site-packages/gevent/pywsgi.py", line 896, in process_result
self.write(data)
File "/var/www/html/py35_ev/lib/python3.5/site-packages/gevent/pywsgi.py", line 742, in write
self._write_with_headers(data)
File "/var/www/html/py35_ev/lib/python3.5/site-packages/gevent/pywsgi.py", line 764, in _write_with_headers
self._write(data)
File "/var/www/html/py35_ev/lib/python3.5/site-packages/gevent/pywsgi.py", line 724, in _write
self._sendall(data)
File "/var/www/html/py35_ev/lib/python3.5/site-packages/gevent/pywsgi.py", line 702, in _sendall
self.socket.sendall(data)
File "/var/www/html/py35_ev/lib/python3.5/site-packages/gevent/_socket3.py", line 408, in sendall
data_memory = _get_memory(data)
File "/var/www/html/py35_ev/lib/python3.5/site-packages/gevent/_socket3.py", line 35, in _get_memory
mv = memoryview(data)
TypeError: memoryview: a bytes-like object is required, not 'str'
Thu Nov 3 11:47:04 2016 {'REMOTE_ADDR': '127.0.0.1', 'REMOTE_PORT': '56104', 'HTTP_HOST': '127.0.0.1:8000', (hidden keys: 23)} failed with TypeError

Mentoring available

Edit: Project not abandoned, mentoring available!

Hai,

This project looks abandoned? I have real site using django-dddp

Generic error wrapper to return Meteor.Error

For example calling an unknown method returns the following:
a["{\"msg\": \"error\", \"error\": \"Unknown method: foo\"}"]

Meteor won't pass errors like the above through to the error argument of the callback (example below).

Django.call('foo', function(error, response) {
  if (error)
    console.log(error);
});

Questions about serialization of related model fields

Thanks for your time on this project. I'm getting back into working with it and it's really great! I had some questions about relations and what data is serialized and sent down to Meteor. I mentioned this before, but apparently related models through foreign keys only serialize and pass down the ID of the object, not access to the other fields.

For example, I have a model that is related to a User. In Meteor I would like to display the name of that user when referencing the object. I tried to add it through annotating with an F expression on the Django queryset, but that doesn't get serialized either. I do see in the api.py serialize method where you check for F expressions, but mine never match the isinstance(val, ExpressionNode) check as val is seen as a unicode string (in the case of the username). I don't know if this is a bug in that method or a user error on my end constructing the expression. The value is there, but it never gets serialized.

My workaround was that I just added in a bit at the end of your serialize method that finds all methods marked as a @Property and then serialize and add them to the payload that's returned. This works great and I like to use properties on my models anyway, so this works fine for me. ( I can put up a pull request for this if you think it's useful )

But I'm surely missing something on how to do this otherwise -- so what is the recommended way to work with additional fields on related objects in this way?

Subscription error for meteor_autoupdate_clientVersions gets 404

With dddp 0.19.0, I started seeing this error bubble up to the client:

autoupdate subscription failed: M…r.m…e.errorClass {error: 404, reason: "Subscription not found", details: undefined, message: "Subscription not found [404]", errorType: "Meteor.Error"} - referring to meteor_autoupdate_clientVersions

I found that the addition of the id_ in the websocket send bit of do_sub method (line 703 of api.py) is causing the error to now show. Prior to 0.19.0, this publication error occurred in dddp, but never showed up on the client, it seems.

Everything appears to work just fine, but the error will show up many times on the client as Meteor retries the subscription. So, with that, does this mean that dddp needs a subscription endpoint for it, or should the do_sub function silently ignore the error? I believe that meteor_autoupdate_clientVersions is a client-only local collection and isn't on the server anyway.

Deployment via gunicorn?

Hi there,

Firstly, thanks for working on this project.

I'm wondering if anyone is using this in production, and/or if there's any reasons to not consider it for production use at this point?

Also on that topic, does anyone have any example code on how this would be deployed in a production environment using gunicorn? I'm guessing it's more complicated than simply pointing gunicorn at the dddp command.

Many thanks,
Richard

KeyError at / 'REMOTE_PORT'

/srv/py/python3/lib/python3.4/site-packages/dddp/views.py in get

 256.                           request.META['REMOTE_ADDR'], request.META['REMOTE_PORT'],

python==3.4, django==1.8.6

Reactive joins for publications with `user_rel`

(From https://gitter.im/commoncode/django-ddp?at=56551f41bcd12a10513a0be3)

Given the Assessment model:

class Assessment(models.Model):
    invited = models.ManyToManyField('auth.user')

Then the following collection will only send Assessments to each user in invited:

class Assessment(Collection):

    """Assessment DDP Collection."""

    model = assessment.Assessment
    user_rel = [
       'invited',
    ]

Django DDP will allow the object to be seen if the user is mentioned in ANY of the fields referenced in user_rel (it applies the OR operator).

Unfortunately I haven't figured out a way to efficiently follow joins in publications yet: we currently have no reactive joins.

Oh hey, I just figured out how to do efficient reactive user_rel publications!

Note to future self implementing reactive user_rel publications:

  • Only re-process publications for the users mentioned in pre and post change.

eg: signals.m2m_changed(action='pre_add', instance=<User>) -> only re-process subscriptions for <User>.

KeyError: 'backend' if SqLite

Hello!

I'm using Sqlite Db in my project and starting using django-ddp:

  File "/Users/user/Desktop/HuskyJam/common_venv/lib/python3.4/site-packages/dddp/apps.py", line 28, in ready
    alias, conf['backend'],
KeyError: 'backend'

Ok, now I know, that django-ddp is working only with postgres, but Exception is not reasonable because default sqlite config has no 'backend':

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

As I see in code, Exception have to contain "django-ddp only works with PostgreSQL":

 def ready(self):
        """Initialisation for django-ddp (setup lookups and signal handlers)."""
        if not settings.DATABASES:
            raise ImproperlyConfigured('No databases configured.')
        for (alias, conf) in settings.DATABASES.items():
            if conf['ENGINE'] != 'django.db.backends.postgresql_psycopg2':
                raise ImproperlyConfigured(
                    '%r uses %r: django-ddp only works with PostgreSQL.' % (
                        alias, conf['backend'],
                    )
                )
        self.api = autodiscover()
        self.api.ready()

Use Django authentication from client side DDP Client

I am trying to integrate a DDP Client into my Django app on the client side as explained here.

I believe from the post, that everything should work fine, except that I want to add an authentication layer for my publish and subscribe calls. Only a "check" for userLoggedIn to determine if the client is authorized to subscribe is enough.

However, I plan to have the user login done through Django and I want to modify the authentication check in Meteor to use the Django authentication system.

Any idea how I can use the DDP "request" from the DDP client to determine if the user has already been authenticated by Django or not.

I am new to DDP and Django (!) and wondering if there are any session type things in the DDP "request" that I can use on the server side to determine if the user has been authenticated by Django already.

I hope I am able to explain it clearly ... Please help!

What is your experience using this app?

Hi guys,

I am looking into meteor right now and the only thing keeping me away is the nosql mongodb database.
This module looks like the solution!!!

Can you tell me about your experience using it?
Are you using it in production?
Are you happy with it?
Are there any problems that might occur?
Do all meteor-functions work?

I'd really love to hear some feedback.

Kind regards
Mikey

no tutorial

I am a newbie in angular and i have recently try django.
I have searched a complete tutorial from zero for using django ddp which seems to be the greatest web technology that i ever touch, but there is a crucial lack of it avoiding me to use django ddp.
I think it could be such a good idea to make a simple one with every state of the set up and a demo, Or if a such tutorial exist to link it in the documentation.

Anyway great job and still try harding on django ddp

MySQL support

Please collect ideas and links under this issue here. I've heard of Facebook's fork of MySQL with listen/notify support. Any links? PostgreSQL docs say that listen/notify are not standard SQL. Is there a way to implement live in a database independent manner.

function' object has no attribute 'im_self

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/srv/js/lib/python3.4/site-packages/django/core/management/__init__.py", line 351, in execute_from_command_line
    utility.execute()
  File "/srv/js/lib/python3.4/site-packages/django/core/management/__init__.py", line 325, in execute
    django.setup()
  File "/srv/js/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/srv/js/lib/python3.4/site-packages/django/apps/registry.py", line 115, in populate
    app_config.ready()
  File "/srv/js/lib/python3.4/site-packages/dddp/apps.py", line 31, in ready
    self.api = autodiscover()
  File "/srv/js/lib/python3.4/site-packages/dddp/__init__.py", line 137, in autodiscover
    autodiscover_modules('ddp', register_to=API)
  File "/srv/js/lib/python3.4/site-packages/django/utils/module_loading.py", line 74, in autodiscover_modules
    import_module('%s.%s' % (app_config.name, module_to_search))
  File "/opt/py3/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/srv/js/lib/python3.4/site-packages/dddp/ddp.py", line 24, in <module>
    API.register([Logs])
  File "/srv/js/lib/python3.4/site-packages/dddp/api.py", line 796, in register
    self.clear_api_path_map_cache()
  File "/srv/js/lib/python3.4/site-packages/dddp/api.py", line 206, in clear_api_path_map_cache
    if api_provider.clear_api_path_map_cache.im_self is not None:
AttributeError: 'function' object has no attribute 'im_self'

Python == 3.4.3, Django == 1.8.5, gevent == 1.1b7.dev0

Example Usage more clearer documentation

Hi,

I'm sorry for this question I am not yet an expert to both django and meteorjs. I am trying to use this django-ddp technology but I am a little stuck on "Start the Django DDP service" on the Example Usage

I created a virtualenv,
I created a project named tutorial,
I followed the example usage instructions from the start until,
Every time I tried to run this command (DJANGO_SETTINGS_MODULE=tutorial.settings dddp) in shell I always get a response of "ImportError: No module named tutorial.settings"

P.S.: I even tried to package the project dir but still no luck.

I really like to practice and use django-ddp ever since I watched your presentation in pycon AU at youtube.

Reduce not found in dddp/views.py

I'm getting the below error

Environment:

Request Method: GET
Request URL: http://localhost:8000/

Django Version: 1.8.5
Python Version: 3.4.3
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'dddp',
'todo.django_todos')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware')

Traceback:
File "/home/kj/.virtualenvs/django-ddp/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response

  1.                 response = wrapped_callback(request, _callback_args, *_callback_kwargs)
    
    File "/home/kj/.virtualenvs/django-ddp/lib/python3.4/site-packages/django/views/generic/base.py" in view
  2.         self = cls(**initkwargs)
    
    File "/home/kj/.virtualenvs/django-ddp/lib/python3.4/site-packages/dddp/views.py" in init
  3.     self.meteor_settings = reduce(
    

Exception Type: NameError at /
Exception Value: name 'reduce' is not defined

Issue when accessing todos-list from admin

this is the error i'm getting - using python 2.7

ProgrammingError at /admin/django_todos/task/

relation "django_todos_task" does not exist LINE 1: SELECT COUNT(*) AS "__count" FROM "django_todos_task"

Exception Value: relation "django_todos_task" does not exist LINE 1: SELECT COUNT(*) AS "__count" FROM "django_todos_task"

Can't find demo project `wsgi` module

When running dddp for https://github.com/tysonclugg/django-ddp-example (which has no wsgi.py file) the following error occurs:

$ dddp --settings=todo.todo.settings
Traceback (most recent call last):
  File "/home/tclugg/.virtualenvs/django-ddp/bin/dddp", line 9, in <module>
    load_entry_point('django-ddp==0.18.0', 'console_scripts', 'dddp')()
  File "/home/tclugg/projects/django-ddp/dddp/main.py", line 338, in main
    verbosity=namespace.verbosity,
  File "/home/tclugg/projects/django-ddp/dddp/main.py", line 268, in serve
    launcher = DDPLauncher(debug=verbosity == 3, verbosity=verbosity)
  File "/home/tclugg/projects/django-ddp/dddp/main.py", line 114, in __init__
    self.wsgi_app = import_string(self.wsgi_name)
  File "/home/tclugg/.virtualenvs/django-ddp/lib/python3.4/site-packages/django/utils/module_loading.py", line 26, in import_string
    module = import_module(module_path)
  File "/home/tclugg/.virtualenvs/django-ddp/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked
ImportError: No module named 'todo.wsgi'

Stable enough for long-term usage?

This is a question, no bug.

  1. I'm just asking wether django-ddp is considered stable enough to be used for a medical application, where data loss/failure is a more-or-less no-go, and should be maintainable for many years.
    How stable is django-ddp considered to be for that?
    Would you recommend it for using in a "data loss critical" environment?

I know that this question is a bit broad, and answers maybe opinion-based, but I want to ask it nevertheless.

  1. Is django-ddp on the server and python-ddp on the client a stable option? Any experiences here?
    Thank you very much.

Python 3 support with gevent beta

I suppose someone had to ask for it. But it would be great to have python 3 support now that gevent==1.1b2 has it. (well you did mention it in your recent pycon Oz talk)

Start documentation

Documentation needs to be written and published covering all aspects of using Django DDP.

dddp.AlreadyRegistered: API with prefix '/' is already registered to <dddp.ddp.Logs object at 0x7fd5d1a2d4a8>

Hello,

Got an issue when i'm using gevent 1.1b6 (python3.4 and django 1.8)

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/kj/.virtualenvs/freelance/lib/python3.4/site-packages/django/core/management/__init__.py", line 351, in execute_from_command_line
    utility.execute()
  File "/home/kj/.virtualenvs/freelance/lib/python3.4/site-packages/django/core/management/__init__.py", line 325, in execute
    django.setup()
  File "/home/kj/.virtualenvs/freelance/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/kj/.virtualenvs/freelance/lib/python3.4/site-packages/django/apps/registry.py", line 115, in populate
    app_config.ready()
  File "/home/kj/.virtualenvs/freelance/lib/python3.4/site-packages/dddp/apps.py", line 31, in ready
    self.api = autodiscover()
  File "/home/kj/.virtualenvs/freelance/lib/python3.4/site-packages/dddp/__init__.py", line 137, in autodiscover
    autodiscover_modules('ddp', register_to=API)
  File "/home/kj/.virtualenvs/freelance/lib/python3.4/site-packages/django/utils/module_loading.py", line 74, in autodiscover_modules
    import_module('%s.%s' % (app_config.name, module_to_search))
  File "/home/kj/.virtualenvs/freelance/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/home/kj/.virtualenvs/freelance/lib/python3.4/site-packages/dddp/accounts/ddp.py", line 568, in <module>
    API.register([Users, LoginServiceConfiguration, LoggedInUser, Auth])
  File "/home/kj/.virtualenvs/freelance/lib/python3.4/site-packages/dddp/api.py", line 792, in register
    self._registry[api.api_path_prefix],
dddp.AlreadyRegistered: API with prefix '/' is already registered to <dddp.ddp.Logs object at 0x7fd5d1a2d4a8>

suggestion - demo project example

Some parts from readme are not clear for me, especially paths and urls when i want integrate django-ddp as the primary DDP. It will be nice if i can look into demo project, it can be an example with bookstore from readme

Test suite

Write tests and document how developers can run them.

Current gevent version not supported

Hi,

Getting the below error when attempting to migrate the database.

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/kj/.virtualenvs/meteor-django/lib/python3.4/site-packages/django/core/management/__init__.py", line 351, in execute_from_command_line
    utility.execute()
  File "/home/kj/.virtualenvs/meteor-django/lib/python3.4/site-packages/django/core/management/__init__.py", line 325, in execute
    django.setup()
  File "/home/kj/.virtualenvs/meteor-django/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/kj/.virtualenvs/meteor-django/lib/python3.4/site-packages/django/apps/registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "/home/kj/.virtualenvs/meteor-django/lib/python3.4/site-packages/django/apps/config.py", line 86, in create
    module = import_module(entry)
  File "/home/kj/.virtualenvs/meteor-django/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/home/kj/.virtualenvs/meteor-django/lib/python3.4/site-packages/dddp/__init__.py", line 5, in <module>
    from gevent.local import local
  File "/home/kj/.virtualenvs/meteor-django/lib/python3.4/site-packages/gevent/__init__.py", line 41, in <module>
    from gevent.hub import get_hub, iwait, wait
  File "/home/kj/.virtualenvs/meteor-django/lib/python3.4/site-packages/gevent/hub.py", line 289
    except Exception, ex:

The requirements.txt file still installs gevent 1.0.2. Should it be gevent 1.1b7?

I tried installing gevent 1.1b7 and after some minor tweaks to the django model (for the to-do example) - I get the below error:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/kj/.virtualenvs/meteor-django/lib/python3.4/site-packages/django/core/management/__init__.py", line 351, in execute_from_command_line
    utility.execute()
  File "/home/kj/.virtualenvs/meteor-django/lib/python3.4/site-packages/django/core/management/__init__.py", line 325, in execute
    django.setup()
  File "/home/kj/.virtualenvs/meteor-django/lib/python3.4/site-packages/django/__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/kj/.virtualenvs/meteor-django/lib/python3.4/site-packages/django/apps/registry.py", line 115, in populate
    app_config.ready()
  File "/home/kj/.virtualenvs/meteor-django/lib/python3.4/site-packages/dddp/apps.py", line 31, in ready
    self.api = autodiscover()
  File "/home/kj/.virtualenvs/meteor-django/lib/python3.4/site-packages/dddp/__init__.py", line 141, in autodiscover
    autodiscover_modules('ddp', register_to=API)
  File "/home/kj/.virtualenvs/meteor-django/lib/python3.4/site-packages/django/utils/module_loading.py", line 74, in autodiscover_modules
    import_module('%s.%s' % (app_config.name, module_to_search))
  File "/home/kj/.virtualenvs/meteor-django/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/home/kj/Desktop/django-meteor/todo/django_todos/ddp.py", line 16, in <module>
    Tasks,
  File "/home/kj/.virtualenvs/meteor-django/lib/python3.4/site-packages/dddp/api.py", line 787, in register
    if api.api_path_prefix in self._registry:
AttributeError: 'Task1' object has no attribute 'api_path_prefix'

Arguments to Publication.get_queries()

I'm running into issues when defining get_queries() on publications with additional/optional arguments.

This is the example from the docs of passing an argument to get_queries:

class BooksByAuthorEmail(Publication):
    def get_queries(self, author_email):
        return [
            models.Author.objects.filter(
                email=author_email,
            ),
            models.Book.objects.filter(
                author__email=author_email,
            ),
        ]

Looks straight-forward enough, however on experimentation it appears that an additional parameter is injected at the start (a named tuple called 'Env' containing the user and subscription created time). So I assumed that the docs were out of date, and it should actually be this:

class BooksByAuthorEmail(Publication):
    def get_queries(self, env, author_email):
        return [
            models.Author.objects.filter(
                email=author_email,
            ),
            models.Book.objects.filter(
                author__email=author_email,
            ),
        ]

The Env argument is actually quite handy. However, even then there appear to be times when get_queries is called with no arguments at all, or with False as the first parameter. The end result is that making any kind of assumption about arguments passed to get_queries quickly ends in a TypeError and the whole process freezes up.

Traceback (most recent call last):
  File "/home/richard/.pyenv/versions/playversity/src/dddp/dddp/websocket.py", line 276, in process_ddp
    self.dispatch(msg, data)
  File "/home/richard/.pyenv/versions/playversity/local/lib/python2.7/site-packages/django/utils/decorators.py", line 184, in inner
    return func(*args, **kwargs)
  File "/home/richard/.pyenv/versions/playversity/src/dddp/dddp/websocket.py", line 351, in dispatch
    handler(**kwargs)
  File "/home/richard/.pyenv/versions/playversity/src/dddp/dddp/websocket.py", line 476, in recv_method
    self.api.method(method, params, id_)
  File "/home/richard/.pyenv/versions/playversity/src/dddp/dddp/api.py", line 768, in method
    result = handler(*params)
  File "/home/richard/.pyenv/versions/playversity/src/dddp/dddp/accounts/ddp.py", line 469, in login
    return self.login_with_resume_token(params)
  File "/home/richard/.pyenv/versions/playversity/src/dddp/dddp/accounts/ddp.py", line 514, in login_with_resume_token
    self.do_login(user)
  File "/home/richard/.pyenv/versions/playversity/src/dddp/dddp/accounts/ddp.py", line 441, in do_login
    self.update_subs(user.pk)
  File "/home/richard/.pyenv/versions/playversity/src/dddp/dddp/accounts/ddp.py", line 267, in update_subs
    in API.sub_unique_objects(sub, params, pub)
  File "/home/richard/.pyenv/versions/playversity/src/dddp/dddp/api.py", line 629, in sub_unique_objects
    in pub.user_queries(sub.user, *params)
  File "/home/richard/.pyenv/versions/playversity/src/dddp/dddp/api.py", line 558, in user_queries
    return get_queries(*params)
TypeError: get_queries() takes at least 2 arguments (1 given)
TypeError('get_queries() takes at least 2 arguments (1 given)',)
> /home/richard/.pyenv/versions/playversity/src/dddp/dddp/api.py(558)user_queries()
    557         try:
--> 558             return get_queries(*params)
    559         finally:

Combining that with optional arguments makes the whole thing unworkable and I'm reduced to trying to derive what arguments are being passed from *args or **kwargs.

Am I missing something here?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.