Coder Social home page Coder Social logo

Comments (5)

maxtepkeev avatar maxtepkeev commented on July 27, 2024 1

Okay, you convinced me ;-)

I like your idea about per session field names memorization, but I don't think it will work, because if a first object in a queue won't have a requested field an exception will be thrown anyway.

So I believe the option 2 is the best we can do. I added the raise_attr_exception kwarg to Redmine object which defaults to True to not break existing code. See 11d3f5e. You can set it to False to completely disable the ResourceAttrError or you can give it a list or tuple of resource class names and it will continue to raise an exception only for this types of resources. All other resources will return None and remain silent. Details can be found in the documentation.

Please reopen if anything isn't working like it should. Thanks.

from python-redmine.

maxtepkeev avatar maxtepkeev commented on July 27, 2024

Only two things come to my mind at the moment:

  1. We can hardcode all the valid attributes for each resource and then check if a requested attribute is in the list of valid attributes we fail silently. But this is what I always trying to avoid, for example if a new version of Redmine will be released and there will be some new fields we will have to add them to this list of valid attributes every time. Not good.
  2. Add a global or per resource option whether to raise an exception if an unset attribute is requested. This will solve this problem but it may give you another problems, e.g. imagine you mistyped a resource attribute (issue.subjekt) and it won't tell you anything about it and you won't get any subject of course. Not good also.

What do you think ?

from python-redmine.

andreiavram avatar andreiavram commented on July 27, 2024

I agree that a solution to such a problem is not available without some sort of compromise. I also agree that the first solution you listed would be a support nightmare.

But the second, if it's given as a constructor parameter for the main Redmine object or wherever, is a "risk" the user takes - just like setting https request verification to False - I find this less of a problem.

I hit this problem while listing issues inside a template, some had an optional field set, some didn't. For this case, a different kind of compromise can be imagined: each Redmine session could infer existing field names for the current connection for each resource type, and return None in getattr whenever we know this field existed in at least one resource of this type, not necessarily the current one.

This will at least give the connector knowledge of the fields that it received up to one point. These may very well not be all fields, but it might be a step forward (also, at least in some usecases, an user is less likely to request attrs that none of the resources he requested has, right?)

from python-redmine.

andreiavram avatar andreiavram commented on July 27, 2024

Great, thanks!

from python-redmine.

aman1792 avatar aman1792 commented on July 27, 2024

It turned out very useful.

from python-redmine.

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.