Git Product home page Git Product logo

django_injector's People

Contributors

blubber avatar diachkow avatar jstasiak avatar vaunorage avatar whysage avatar wmeints 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

Watchers

 avatar  avatar  avatar

django_injector's Issues

Problem doing dependency injection in DRF

When I try to access through the browser, it throws me this error:

Screenshot_2021-03-24 TypeError at api v1 comics

This is my code:

ComicListAPIView

Module:

ComicModule

Injector config:

injector config

But this only happens from the browser! From the client like Postman, no.

Captura de pantalla_2021-03-24_10-51-43

What's going on? ๐Ÿ˜•

Error 'DjangoInjectorModule' object has no attribute '__name__' when running server

I made my configuration like so :

`INSTALLED_APPS = [
'django_injector',
]

MIDDLEWARE = [
'django_injector.middleware.inject_request_middleware'
]

INJECTOR_MODULES = [
'garderie.manager.bidings.Container'
]`

I have my bindings like this :

class Container(Module): def configure(self, binder): binder.bind(DateUtils, to='DateUtils') binder.bind(PaymentService, to='PaymentService') binder.bind(PaymentSynchronizer, to='PaymentSynchronizer') binder.bind(PaymentScheduler, to='PaymentScheduler') binder.bind(PaymentAPIService, to='PaymentAPIService') binder.bind(PaymentAPIImpl, to='PaymentAPIImpl') binder.bind(PaymentAPIMapper, to='PaymentAPIMapper') binder.bind(InscriptionService, to='InscriptionService')

yet I get this error when I run my server :

AttributeError: 'DjangoInjectorModule' object has no attribute '__name__'

An invitation to look at the dependencies library.

Hi,

I'm the creator of the dry-python project. We have an alternative dependency injection library: dependencies.

I hope you can take a look at it and provide some feedback to us.

We have Django and REST Framework integration as well:

I know the issue tracker isn't the best way to share ideas. Forgive me if it confuses you in any way.

Best regards,
Artem.

Issue with graphene-django csrf_exempt

Hi!

May be this info will save some time to users.

Issue description:

  1. Add graphene-django to django project
  2. Use csrf_exempt for graphql/
    urlpatterns = [
    ...
    path("graphql/", csrf_exempt(GraphQLView.as_view(graphiql=True, schema=schema)), name='graphql'),
    ...
    ]
  3. csrf_exempt will not work :-(

The reason (as I understant, it's may be wrong) is than django_injector adds wrapper to view GraphQLView and removes
.csrf_exempt = True
from view

Just for now I removed django_injector from project, because for me just injector works good with graphene-django
But may be it will be good to solve this issue.

Scope for apps

I haven't found how to do dependency injection for a specific application, it can only be done globally, it would be convenient to add scope for a specific django apps:

class PollsClientModule(Module):
     @app("polls")
     @singleton
     @provider
     def provide_client(self) -> ABCMyClient:
           ...
           
class CatsClientModule(Module):
     @app("cats")
     @singleton
     @provider
     def provide_client(self) -> ABCMyClient:
           ...

polls/views.py:

def index_view(request: HttpRequest, client: ABCMyClient) -> HttpResponse:  # ABCMyClient from PollsClientModule
    ...

cats/views.py:

def index_view(request: HttpRequest, client: ABCMyClient) -> HttpResponse:  # ABCMyClient from CatsClientModule
    ...

Migrating from 0.2.5 to 0.3.1

Hello everyone, after updating the library to the latest version, I try to run my project but I get the following error related to this library, do you have any idea why it could be happening?

I have the following libraries installed:

  • Django==4.0.4
  • djangorestframework==3.14.0

In addition to the above, the following tests were performed, but they did not work either:
1 - Django and DRF in current version (4.0.4 and 3.xx) and updating Django-Injector version to 0.3.1.
2- Django and DRF to the latest version without upgrading Django-Injector (0.2.5)
3- Django and DRF to the latest version with the latest version of Django-Injector (0.3.1)

  File "/Users/jrosalesmeza/Desktop/apps/app/.venv/lib/python3.11/site-packages/django/utils/module_loading.py", line 32, in import_string
    raise ImportError(
ImportError: Module "django_injector" does not define a "inject_request_middleware" attribute/class

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/opt/homebrew/Cellar/[email protected]/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "/opt/homebrew/Cellar/[email protected]/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "/Users/jrosalesmeza/Desktop/apps/app/.venv/lib/python3.11/site-packages/django/utils/autoreload.py", line 64, in wrapper
    fn(*args, **kwargs)
  File "/Users/jrosalesmeza/Desktop/apps/app/.venv/lib/python3.11/site-packages/django/core/management/commands/runserver.py", line 157, in inner_run
    handler = self.get_handler(*args, **options)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jrosalesmeza/Desktop/apps/app/.venv/lib/python3.11/site-packages/django/core/management/commands/runserver.py", line 78, in get_handler
    return get_internal_wsgi_application()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/jrosalesmeza/Desktop/apps/app/.venv/lib/python3.11/site-packages/django/core/servers/basehttp.py", line 49, in get_internal_wsgi_application
    raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: WSGI application 'config.wsgi.application' could not be loaded; Error importing module.

module not found

Hello,

First of all thank you for your amazing work.

On the new version 0.3.0 the package is not fully downloaded.

Problems with inject decorator at 0.2.0

Thank you for a nice package, but I have an issue with novel version.
Python version 3.9.1
Django version 3.1.6

That code example raises an exception

from injector import inject

class Command(BaseCommand):
    """ Remove expired login tokens """
    help = 'Remove expired tokens'

    @inject
    def __init__(self, case: RemoveExpiredRestoreTokens, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._case: RemoveExpiredRestoreTokens = case

    def handle(self, *args, **options):
        self._case.execute()
        self.stdout.write(self.style.SUCCESS('Expired restore tokens were removed'))

Exception

Traceback (most recent call last): File "/code/manage.py", line 22, in <module> main() File "/code/manage.py", line 18, in main execute_from_command_line(sys.argv) File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line utility.execute() File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 244, in fetch_command klass = load_command_class(app_name, subcommand) File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 38, in load_command_class return module.Command() TypeError: __init__() missing 1 required positional argument: 'case'

But it works on previous version of package (0.1.1) with the usage of modified inject decorator for django-inject package

from django_injector import inject

class Command(BaseCommand):
    """ Remove expired login tokens """
    help = 'Remove expired tokens'

    @inject  # type: ignore
    def __init__(self, case: RemoveExpiredRestoreTokens, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._case: RemoveExpiredRestoreTokens = case

    def handle(self, *args, **options):
        self._case.execute()
        self.stdout.write(self.style.SUCCESS('Expired restore tokens were removed'))

Also now is absent ability to inject into functions and inject Injector itself. If you need access to Container
Smth like this

from django_injector import inject
from injector import Injector


@inject
def get_container(injector: Injector) -> Injector:
    """ Returns container instance """
    return injector

Can you suggest smth or I should use previous version?

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.