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

sgqlc-codegen fails with AttributeError: 'ObjectValueNode' object has no attribute 'value' #187

Open
4ekin opened this issue Feb 1, 2022 · 5 comments
Assignees
Labels
bug Something isn't working waiting-input

Comments

@4ekin
Copy link

4ekin commented Feb 1, 2022

Hello!
Great lib, really great, thank you for your work!

Eventually I wanted to update my api adapter and during codegen operation it fails

$sgqlc-codegen schema api_schema.json api_schema.py

Traceback (most recent call last):Traceback (most recent call last):  File "/home/eugene/.local/share/virtualenvs/ptal_kb_api-JL_OxvTL/bin/sgqlc-codegen", line 8, in <module>    sys.exit(main())  File "/home/eugene/.local/share/virtualenvs/ptal_kb_api-JL_OxvTL/lib/python3.8/site-packages/sgqlc/codegen/__init__.py", line 130, in main    args.func(args)  File "/home/eugene/.local/share/virtualenvs/ptal_kb_api-JL_OxvTL/lib/python3.8/site-packages/sgqlc/codegen/schema.py", line 681, in handle_command    gen.write()  File "/home/eugene/.local/share/virtualenvs/ptal_kb_api-JL_OxvTL/lib/python3.8/site-packages/sgqlc/codegen/schema.py", line 164, in write    self.write_types()
  File "/home/eugene/.local/share/virtualenvs/ptal_kb_api-JL_OxvTL/lib/python3.8/site-packages/sgqlc/codegen/schema.py", line 261, in write_types
    mapped(t)
  File "/home/eugene/.local/share/virtualenvs/ptal_kb_api-JL_OxvTL/lib/python3.8/site-packages/sgqlc/codegen/schema.py", line 495, in write_type_object
    self.write_type_container(t, bases, own_fields, write_field)
  File "/home/eugene/.local/share/virtualenvs/ptal_kb_api-JL_OxvTL/lib/python3.8/site-packages/sgqlc/codegen/schema.py", line 446, in write_type_container
    write_field(field, siblings)
  File "/home/eugene/.local/share/virtualenvs/ptal_kb_api-JL_OxvTL/lib/python3.8/site-packages/sgqlc/codegen/schema.py", line 424, in write_field_output
    self.write_arg(a, siblings)
  File "/home/eugene/.local/share/virtualenvs/ptal_kb_api-JL_OxvTL/lib/python3.8/site-packages/sgqlc/codegen/schema.py", line 398, in write_arg
    defval = repr(parse_graphql_value_to_json(defval))
  File "/home/eugene/.local/share/virtualenvs/ptal_kb_api-JL_OxvTL/lib/python3.8/site-packages/sgqlc/codegen/schema.py", line 72, in parse_graphql_value_to_json
    v = v.value
AttributeError: 'ObjectValueNode' object has no attribute 'value'

Version from Pipfile.lock -

"sgqlc": {
            "hashes": [
                "sha256:6705ed48683cd48b3c3252ca737be67abb7bc790ac5749c0d806c3f36320f720",
                "sha256:c74c9e657ee7409486aaccbffddf369c048b8b262e15b3516d96c51b86bde176"
            ],
            "index": "pypi",
            "version": "==15.0"
        },

Can you help me?

@4ekin
Copy link
Author

4ekin commented Feb 1, 2022

Seems it fails on generating this arg:

{
                  "defaultValue": "{performSynchronously: true}",
                  "description": null,
                  "name": "performanceControl",
                  "type": {
                    "kind": "INPUT_OBJECT",
                    "name": "PerformSynchronously",
                    "ofType": null
                  }
                },

with type:

{
          "description": null,
          "enumValues": null,
          "fields": null,
          "inputFields": [
            {
              "defaultValue": "true",
              "description": null,
              "name": "performSynchronously",
              "type": {
                "kind": "SCALAR",
                "name": "Boolean",
                "ofType": null
              }
            }
          ],
          "interfaces": null,
          "kind": "INPUT_OBJECT",
          "name": "PerformSynchronously",
          "possibleTypes": null
        },

@barbieri
Copy link
Member

barbieri commented Feb 1, 2022

could you share a reproducible example? Other than that, it seems that newer version of graphql-core may be an issue, could you check which version are you using? See #186

@barbieri barbieri self-assigned this Feb 1, 2022
@barbieri barbieri added the bug Something isn't working label Feb 1, 2022
@4ekin
Copy link
Author

4ekin commented Feb 7, 2022

could you share a reproducible example? Other than that, it seems that newer version of graphql-core may be an issue, could you check which version are you using? See #186

Sorry for long answer
Version of graphql-core is 3.1.6

$python3 -m pipenv run pip freeze

certifi==2021.10.8
charset-normalizer==2.0.8
ecdsa==0.17.0
graphql-core==3.1.6
idna==3.3
pyasn1==0.4.8
python-jose==3.3.0
python-keycloak==0.26.1
requests==2.26.0
rsa==4.8
sgqlc==14.1
six==1.16.0
urllib3==1.26.7

I've tried do all my best for minimal reproducible example
min_api_schema.txt

If I remove arg on 111 line (PerformSynchronously) it successfully generates classes.

@barbieri
Copy link
Member

@4ekin is it still happening with the latest releases?

@4ekin
Copy link
Author

4ekin commented Aug 11, 2022

@4ekin is it still happening with the latest releases?

Hi, sorry for long answer
Actually yes
But I dont know is it problem on your side

Well, graphql-core doc for class Visitor says that if you want to stop visiting you should use BREAK value
https://github.com/graphql-python/graphql-core/blob/main/src/graphql/language/visitor.py#L82

But when their implementation of visit func leave from node, it checks BREAK and True values.

Your Visitor implemetation returns bool value for BooleanNode, and in my case during parsing

"defaultValue": "{performSynchronously: true}",

it returns True, and graphql-core visit func decide to BREAK visiting, and your Visitor callback https://github.com/profusion/sgqlc/blob/master/sgqlc/codegen/schema.py#L52 does not work.

If I change https://github.com/graphql-python/graphql-core/blob/main/src/graphql/language/visitor.py#L263 to

if result is BREAK:

for me it works ideal.

What do you think about it @barbieri , is it core bug?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working waiting-input
Projects
None yet
Development

No branches or pull requests

2 participants