Giter Club home page Giter Club logo

Comments (13)

sbwhitney avatar sbwhitney commented on July 20, 2024 3

Good news. I figured out what the root cause is. It turns out that the way we're importing is causing the issue.

@root_validator would fail when we do this:

from fhir.resources.capabilitystatement import CapabilityStatement

I resolved the conflict by doing this:

from fhir.resources import capabilitystatement

This seems to be a very narrow edge case when we deploy lambdas to localstack.

from fhir.resources.

sbwhitney avatar sbwhitney commented on July 20, 2024

Perhaps we would need to set the boolean to True for allow_reuse wherever @root_validator is called:

https://github.com/samuelcolvin/pydantic/blob/31bc2435d7968fdf8d1f0c5c67f0f851c1bef54e/pydantic/class_validators.py#L106

from fhir.resources.

nazrulworld avatar nazrulworld commented on July 20, 2024

@sbwhitney thanks a lot for reporting this issue, do you add more root validator on CapabilityStatement or any custom root validator added named validate_required_primitive_elements
Just trying to understand to reproduce this error :)

from fhir.resources.

sbwhitney avatar sbwhitney commented on July 20, 2024

We don't add any additional root validator.

from fhir.resources.

nazrulworld avatar nazrulworld commented on July 20, 2024

@sbwhitney
I have spent some time on this error, which seems interesting to me and also a bit unusual (I cannot re-produce in my local).

As far as I understand the reason might be cache or thread or Jenkin container issue (I really don't have the full idea) if you look at here https://github.com/samuelcolvin/pydantic/blob/31bc2435d7968fdf8d1f0c5c67f0f851c1bef54e/pydantic/class_validators.py#L44
This _FUNCS container might not empty! (first time when you imports, container got values) (even you redeploy a second time) but normally when the python interpreter restarted that container be empty. Not sure how AWS Jenkin docker is working. I am really curious to find the exact reason.

Is it possible somehow manually empty that container _FUNCS, before running your Lambda functional running (maybe a stupid question :))

As per your suggestion by enabling reuse true, might fully solve this problem, but we have to compromise some integrities.
I think we can do that as the last option after analyzing all perspectives, before that let's try to find the real issue.

from fhir.resources.

sbwhitney avatar sbwhitney commented on July 20, 2024

@nazrulworld How would we compromise integrity if we set root_validator to allow_reuse=True?

from fhir.resources.

nazrulworld avatar nazrulworld commented on July 20, 2024

@sbwhitney
´compromise integrity´ meant by me, for example, if two root validators func are created with the same name for a class now we are getting this ConfigError (which is good) and if we reuse true, silently second validator function will work by nature. [honestly speaking this could be a very rare case]

I see you opened an issue at pydantic, which is so nice 👌 , let's see their reaction after then we will make it allow_reuse=True for all our root validators

from fhir.resources.

sbwhitney avatar sbwhitney commented on July 20, 2024

Turns out the issue just moves downstream.

This works:

def create_hin_cap_statement(data, event):
    f_date = datetime.datetime.now()

    metadata = {
        "status": "active",
        "kind": "instance",
        "fhirVersion": "4.0.1",
        "date": f_date,
        "format": ["application/fhir+json"],
        "publisher": "Acme, Inc.",
    }
    cap_statement = capabilitystatement.CapabilityStatement(**metadata)

    return cap_statement.json()

while this doesn't:

def create_hin_cap_statement(data, event):
    f_date = datetime.datetime.now()

    metadata = {
        "status": "active",
        "kind": "instance",
        "fhirVersion": "4.0.1",
        "date": f_date,
        "format": ["application/fhir+json"],
        "publisher": "Acme, Inc.",
    }
    cap_statement = capabilitystatement.CapabilityStatement(**metadata)

    issues_list = []
    required_data = {
        "description": event["product"] + " API",
        "url": os.environ["BASE_URL"]
        + "/"
        + event["product"]
        + "/"
        + event["version"],
    }
    impl = capabilitystatement.CapabilityStatementImplementation(**required_data)
    cap_statement.implementation = impl.dict()

    if len(issues_list) == 0:
        issues_list.append(
            create_issue("information", "No issues creating CapabilityStatement")
        )
    required_data = {"issue": issues_list}
    op_out = operationoutcome.OperationOutcome(**required_data)

    return cap_statement.json(), op_out.dict()

from fhir.resources.

sbwhitney avatar sbwhitney commented on July 20, 2024

Not sure why it works locally and in AWS environment but not localstack. There are 12 methods with the same name in capabilitystatement.py which seems to be the issue:

validate_required_primitive_elements

from fhir.resources.

nazrulworld avatar nazrulworld commented on July 20, 2024

It is working in Travis CI as well without complaining. f_cls.__func__.__module__ + '.' + f_cls.__func__.__qualname__ that should ensure 12 unique name of validate_required_primitive_elements. as those same name 12 methods are individually assigned to 12 classes.

Is this only for capabilitystatement , you are facing this kind of problem or for all?

I am also working on avoiding same name method.

from fhir.resources.

sbwhitney avatar sbwhitney commented on July 20, 2024

Here's an example where the same behavior occurs in ipython and they fixed it specifically for ipython:

pydantic/pydantic#312

from fhir.resources.

sbwhitney avatar sbwhitney commented on July 20, 2024

It is working in Travis CI as well without complaining. f_cls.__func__.__module__ + '.' + f_cls.__func__.__qualname__ that should ensure 12 unique name of validate_required_primitive_elements. as those same name 12 methods are individually assigned to 12 classes.

Is this only for capabilitystatement , you are facing this kind of problem or for all?

I am also working on avoiding same name method.

I'm not certain if it occurs for all but I would assume so.

Thank you so much.

from fhir.resources.

nazrulworld avatar nazrulworld commented on July 20, 2024

@sbwhitney https://pypi.org/project/fhir.resources/6.0.0b10/

from fhir.resources.

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.