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

Action API is inconsistent #473

Merged
merged 32 commits into from
Jun 13, 2013
Merged

Action API is inconsistent #473

merged 32 commits into from
Jun 13, 2013

Conversation

domoritz
Copy link
Contributor

This pr is not supposed to make everything correct but to make it better that it is at the moment and refactor some code to a point from which we can do more refactoring.


What has changed so far:

  • Many actions do not produce a server error any more if limit and offset is a negative integer or no integer at all. Also validation for other parameters. Kind of breaking because instead of a 500, you get a 409.
  • ParameterError was removed in favour of ValidationError breaking
  • _get_or_bust goes through the validation code (common code paths)
  • _get_or_bust returns a list instead of a single string for a missing field (consistent with validate) breaking
  • Updated docstrings
    • Datastore docs indicate optional parameters
  • current_package_list_with_resources supports offset, page is deprecated
  • Auto complete actions get consistent parameters, q is now required in all auto complete actions breaking, all actions support limit
  • Added tests for changes
  • [package|resource]search have proper parameter validation
  • small fixes...

There are still many functions that have no proper validation. Often bad input is not tested and adding validation takes time because new validation definitions have to be written.

One thing to discuss is whether we want to have basic validation for all action functions in controllers/api instead of in every single action. This would require a parameter schema for every action function.

@tobes
Copy link
Contributor

tobes commented Feb 26, 2013

@domoritz I think ux label is really for front-end syuff so the api would fall outside that even if it is part of the ckan experience

@domoritz
Copy link
Contributor Author

@tobes Okay.

@domoritz
Copy link
Contributor Author

Pointer: https://gist.github.com/seanh/4130567

Otherwise errors occur when doing a deep copy of the context in validate
Conflicts:
	ckan/tests/logic/test_action.py
The problem was that `facet.field` is not always a list of strings but sometimes a string of a python list of strings. Furthermore, needless parameters are reported in search and not in the validation step so that they are reported as SearchQueryErrors and not ValidationErrors.
@domoritz
Copy link
Contributor Author

I think this is ready for review now.

@domoritz
Copy link
Contributor Author

@johnglover I removed the ast code and use json instead. Are there any things left that prevent the merge (apart form getting master into this branch, of course)?

@domoritz
Copy link
Contributor Author

domoritz commented Jun 3, 2013

Concerning the breaking changes: http://xkcd.com/1172/

@johnglover
Copy link
Contributor

@domoritz No I don't think so, I'll merge.

@johnglover
Copy link
Contributor

@domoritz Merged, tests pass locally but have a few failures on Travis, any ideas?
https://travis-ci.org/okfn/ckan/jobs/7978032

@domoritz
Copy link
Contributor Author

Not without further looking into the individual issues.

@johnglover
Copy link
Contributor

Yes, it seems to be specific to this branch though, the last time I merged it was also passing in master but failing here. Perhaps something strange is going on with this branch and Travis...

@domoritz
Copy link
Contributor Author

I restarted the build. Let's see what happens.

@johnglover
Copy link
Contributor

The current test failures are triggered by calling get_or_bust to get the model object from the context dict. The model is going through the validation functions and causing an exception when we try to deepcopy it in augment_data.

@domoritz is going to have a look at this.

@tobes
Copy link
Contributor

tobes commented Jun 12, 2013

@johnglover when you ran the tests locally did you run them all? or just the ckan ones?

try nosetests --ckan --with-pylons=test-core.ini --nologcapture ckan ckanext I've run into this problem and it was due to the datastore tests polluting ckan

specifically

import ckanext.datastore.plugin as plugin in ckanext/datastore/tests/test_configuration.py to be honest that whole file is hopelessly broken

@johnglover
Copy link
Contributor

@tobes This is with just the ckan tests, but with the datastore loaded as a plugin. I think we have a fix for this, which is just to keep get_or_bust as a special case like it currently is (doesn't go through validate) but raises a proper ValidationError.

@domoritz
Copy link
Contributor Author

@tobes Can you elaborate a little bit on "hopelessly broken"?

@tobes
Copy link
Contributor

tobes commented Jun 12, 2013

To be honest I'm not sure where to start.

Essentially you get the plugin and then go in and replace the methods and then test these new methods. It is so broken it makes me cry. I had looked at fixing it but the whole thing is too confused.

The plugins are a mess which I'm trying to fix in #549 but some of the stuff done to get around these problems is dubious and I think that a lot of what is being tested may not be the same as you think is being tested and more specifically often I don't think you actually are testing the plugin but instead a highly modified version of the plugin that the user will never encounter in the wild.

but things like importing a plugin in a test for example causes major issues and should never happen. in this example you permanently have the datastore plugin at least partially enabled for tests when it should not have been present.

@domoritz
Copy link
Contributor Author

Well, this file has unit tests and we had to mock functions so that we only test a single function and not the whole thing. Obviously these tests do not run in a realistic environment since we don't ever talk to the db. If you think that this is not necessary, I'd be happy to delete the whole file.

…because it caused problems with validate on dictionaries with objects such as context
@domoritz
Copy link
Contributor Author

Replacing deepcopy with copy resolves all issues. @kindly has to decide whether this is okay.

@johnglover
Copy link
Contributor

I also think it's fine (and probably preferable) for get_or_bust to not go through the validate function but create a proper ValidationError. Using validate seems like adding unnecessary overhead to what should be a very simple function.

@kindly
Copy link
Contributor

kindly commented Jun 13, 2013

Can not see obvious problem with using copy. The data is flattened and most values are strings so it should not make much difference.
I think deepcopy was used to make sure that if anyone manipulated the input data after it would not effect the contents of result. I do not see that happening though.
So should be fine.

@johnglover
Copy link
Contributor

Ok well if @kindly and @domoritz are both happy with this then I'll merge.

johnglover added a commit that referenced this pull request Jun 13, 2013
@johnglover johnglover merged commit 349e1cb into master Jun 13, 2013
@johnglover johnglover deleted the 473-consistent-api-validation branch June 13, 2013 12:21
@domoritz
Copy link
Contributor Author

Wohooo 💃

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

Successfully merging this pull request may close these issues.

None yet

4 participants