Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with mixins losing model fields #1342

Open
phoebebright opened this issue Sep 11, 2015 · 9 comments
Open

Problem with mixins losing model fields #1342

phoebebright opened this issue Sep 11, 2015 · 9 comments

Comments

@phoebebright
Copy link
Contributor

I'm having an issue with the api report {"error": "No matching 'priority' field for ordering on."}
where priority field is one of the model fields but on tracing the code, self.fields has only the fields from one of the mixins, there are 2, when it gets to apply_sorting. If this is not a known problem and it's not something I'm doing wrong, then I'll see if I can build a test to replicate it.

@SeanHayes
Copy link
Member

I haven't used mixins with Tastypie that much, a test case would be very helpful.

@phoebebright
Copy link
Contributor Author

Havn't had any success getting it to fail in a controlled way yet. Was working with an earlier version of tastypie, so will keep working on it.

@georgedorn
Copy link
Contributor

Can you post (or pastebin) your models.py and your resource definition?
On Sep 11, 2015 11:38 AM, "Phoebe Bright" notifications@github.com wrote:

Havn't had any success getting it to fail in a controlled way yet. Was
working with an earlier version of tastypie, so will keep working on it.


Reply to this email directly or view it on GitHub
#1342 (comment)
.

@phoebebright
Copy link
Contributor Author

Is there something I don't understand about caching?

In preparing the list of resources and doing a final test to make sure I'm not being obviously stupid, I copied my resources called todos to a new one called todostest, stripped it right down and it worked then. So I slowly added back all the methods and properties and I now have two identical resources, one of which works and the other one doesn't.

So I switch the resource_name around. Now the one the was working isn't and visa versa, ie. the one name todos doesn't work and the one name todostest does.

Sounds like a cache problem? Tried different sorts and filters but no way can I persuade the broken one to work. It will return a blank set or complain about the name of most of the fields.

See: http://pastebin.com/CWGBULEK

@SeanHayes
Copy link
Member

Hmm, interesting. I wonder if it has something to do with "canonical" resources.

I'll try to recreate in a test case later.

@SeanHayes
Copy link
Member

@phoebebright Could you add the definition for the todostest resource?

@SeanHayes SeanHayes added this to the v0.13.0 milestone Oct 11, 2015
@phoebebright
Copy link
Contributor Author

This looks like the code from the time I had the problem. Both TodoResource and TodoTestResource should the same as I just copied one and renamed it:

http://pastebin.com/NhvYUT2L

Since then I've split the code and put all the methods into a class and then subclassed ToDoResource and it all seems to work fine. Have not idea how I broke it I'm afraid or what exactly fixed it again. If there is anything I can test, let me know.

@SeanHayes
Copy link
Member

Neither of those resources are using mixins though. Just to confirm, the error was caused when 2 resources shared the same mixin which defined some fields, correct? Did the mixin class itself inherit from Resource or ModelResource, or just from object?

@phoebebright
Copy link
Contributor Author

The problem SEEMED to be caused by having two mixins on the model, tastypie was not able to identify all the fields that should make up that model. I did quite a bit of tracing trying to see what the problem was but never got to the bottom of it. I still have the two mixins and it is now working but sadly can't say what I did that fixed it, hence my thought it might be something to do with cache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants