Skip to content

Thrift 4126#1215

Closed
kufd wants to merge 6 commits intoapache:masterfrom
kufd:THRIFT-4126
Closed

Thrift 4126#1215
kufd wants to merge 6 commits intoapache:masterfrom
kufd:THRIFT-4126

Conversation

@kufd
Copy link
Contributor

@kufd kufd commented Mar 19, 2017

Hello
It is a pull request with required fields validation for php extension
Here is jira issue https://issues.apache.org/jira/browse/THRIFT-4126

Copy link
Contributor

@jeking3 jeking3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many of the Travis CI build jobs failed. That needs to be investigated and resolved.

@kufd
Copy link
Contributor Author

kufd commented Mar 25, 2017

Hi @jeking3
I looked into the failed builds. But errors are not related to my changes.
Maybe i should wait for some time and merge changes from thrift repo into my branch.

@jeking3
Copy link
Contributor

jeking3 commented Mar 25, 2017

Yes, I recommend you:

  1. Squash your commits (optional, but we'll do it anyway when we merge into apache master)
  2. Rebase against upstream master.
  3. Force push.

This will trigger a new build against the tip.
If you are not familiar with squashing, it's okay if you skip that part.

@kufd
Copy link
Contributor Author

kufd commented Mar 27, 2017

Now all build jobs are success

Copy link
Contributor

@jeking3 jeking3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks good and passes all tests (it might be useful to follow this up with a new functional test (see test/functional) that tries to use a structure with a required field that is not set, to see which runtimes allow it and which ones do not (such as php after applying this patch)? It would be nice to see a test verifying the new functionality.

@kufd
Copy link
Contributor Author

kufd commented Mar 27, 2017

Yes
I will add functional tests
But it can take a few weeks, because i do not have enough free time now

@jeking3
Copy link
Contributor

jeking3 commented Mar 27, 2017

I'll open a story in Jira for it. (THRIFT-4142)

if (is_required && Z_TYPE_P(prop) == IS_NULL) {
char errbuf[128];
snprintf(errbuf, 128, "Required field %s.%s is unset!", object_class_entry->name, varname);
throw_tprotocolexception(errbuf, INVALID_DATA);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if folks think it would be useful to add a new TProtocolException cause for this case, MISSING_REQUIRED, across all languages. While technically it is invalid data, I usually think of that as something got garbled.

@jeking3
Copy link
Contributor

jeking3 commented Mar 27, 2017

When this does merge into master, it's probably worth updating the README.md indicating this is a breaking change (for the better). I would like to take a look at how some of the other runtime libraries for Thrift handle required fields as well to see what the consensus behavior is.

Copy link
Contributor

@jeking3 jeking3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a little more research into this and found an old ticket, THRIFT-455, which led me to discover there's really no standardization on how things are handled in this area across the languages. The one takeaway I got from that is that while your changes are indeed an improvement in making required fields actually required (for the binary protocol only, from what I can tell), it is a breaking change and we should probably add a generic compiler flag that works across all languages to say, "required field validation" that can be turned on optionally (default is OFF, preserving existing behavior). Then at some time in the future when all implementations support validation, we would change the default to ON, and eventually phase out the option. Thoughts?

@kufd
Copy link
Contributor Author

kufd commented Mar 30, 2017

There is a falg "validate" in thrift generator for php (validate: Generate PHP validator methods\n")
And that flag is used in my changes
I will try to add tests for both cases: when the flag is set and when not

Copy link
Contributor

@jeking3 jeking3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on last comment, this logic is not engaged unless someone sets the compiler flag "validate" for php generation. This means with default flags there is no breaking change, so I'm approving.

@asfgit asfgit closed this in 1360270 Mar 30, 2017
jeking3 pushed a commit to jeking3/thrift that referenced this pull request Nov 30, 2017
…en validate compiler option is enabled

Client: php

This closes apache#1215
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.

2 participants