Giter Club home page Giter Club logo

Comments (6)

scoder avatar scoder commented on May 31, 2024

from cython.

scrimpys avatar scrimpys commented on May 31, 2024

Have tested latest version - 3.0.7. Problem still occurs.

Not sure how to provide the traceback. The problem is reported in the GUI/Web page when I attempt to make changes to a field in my application.

I have attached a sample application to demonstrate the problem. Use username="sam" and password="Secret_123" to login to the admin screen ( /admin ). You can start the dev server using "python manage.py runserver 0:8000" from the pixel directory.

Further testing shows that the issue arrises when I create a custom save for my model. It does not occur if I don't have a custom save mode. The issue also only occurs only when I compile using Cython.
django_cython_error.tar.gz

The tar archive contains the Django project but you will likely need to install the requirements ( assume you will use a python venv).

The specific part of the code that causes the issue is in admin.py.

   # sample save_model - note indentation not shown

   def save_model(self, request, obj, form, change):
        obj.save()
        print(change)
        if change:
            print("change", change, obj.id)
            if not os.path.isdir(f'/tmp/{obj.id}'):
                os.mkdir(f'/tmp/{obj.id}')

Again - this code only creates the issue when the project is compiled with Cython. There is a setup.py file in the pixel directory that I used to compile the project with command "python setup.py build_ext --inplace"

Please let me know if there is anything else you need.

from cython.

scoder avatar scoder commented on May 31, 2024

Looking through Django's code a bit, there seems to be a metaclass involved for this class: MediaDefiningClass. It doesn't touch this specific method, but at least, it changes the way the class is instantiated. The method itself seems to be very ordinary and overriding it shouldn't harm. Also, the fact that it says "3 arguments given" instead of 5 seems odd. If anything goes wrong with a method, it's usually off by one due to self, not off by two. Difficult to say what's going wrong here.

from cython.

da-woods avatar da-woods commented on May 31, 2024

Not a Cython bug - this is a choice that django-mass-edit has made:

https://github.com/burke-software/django-mass-edit/blob/8f455b1ee05e9d5b7b3e4e5094928b4397fc405b/massadmin/massadmin.py#L125

        for (varname, var) in self.get_overrided_properties().items():
            if not varname.startswith('_') and not isinstance(var, types.FunctionType):
                self.__dict__[varname] = var

Cython functions don't pass the check isinstance(var, types.FunctionType), which checks for an regular Python function. Therefore your CustomerAdmin.save_model gets inappropriately copied over to overwrite MassAdmin.save_model and you end up in some sort of mess.

Cython functions are not regular Python functions by necessity. We made them look as much like Python functions as possible, but we can never pass an isinstance type check.

from cython.

da-woods avatar da-woods commented on May 31, 2024

If you want a reproducible example that doesn't use Cython then change your CustomerAdmin class to be:

class CustomerAdmin(...):  # put in the correct base class

    class Callable:
        def __call__(self, request, obj, form, change):
            ... # implementation of save_model goes here
    save_model = Callable()

This'll demonstrate the (roughly) same issue you see here.

from cython.

scoder avatar scoder commented on May 31, 2024

from cython.

Related Issues (20)

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.