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

Support nullable types #790

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Support nullable types #790

wants to merge 6 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Jan 5, 2023

Hello everyone! 👋

The purpose of this PR is to support nullable types (#523). This allows to use generated messages in this way:

final user = User();
user.firstName = null;
print(user.firstName?.isNotEmpty());

The main advantage of this solution over hazzers is to take advantage of null safety.

Currently, this PR generates nullable types if the field is a message, or if the field is optional in the proto3 sense. Hazzers are still generated. To generate nullable types, you must use the nullable option, which is set to false by default.

I'm sure this PR is not mergeable in its current state (no test added), but I'm opening it to be helped and to ask questions. Don't hesitate to tell me if I'm going in the wrong direction!

  • Why is ArgumentError.checkNotNull(value, 'value') used in $_setFloat for example, in generated_message.dart?
  • Is it a good idea to modify generated_message.dart and field_set.dart?
  • Is it a good idea to add an option to the generator?
  • For tests, is it better to copy the current tests, modifying them to check for nullable types, or is it better to add new tests just for that?
  • Is this feature desired in this package?

Thank you very much in advance!

@google-cla
Copy link

google-cla bot commented Jan 5, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@ghost ghost marked this pull request as draft January 5, 2023 17:50
@ghost ghost marked this pull request as ready for review January 5, 2023 19:09
@yingshaoxo
Copy link

@johynpapin

Hello? Any updates on this?

grpc/grpc-dart#599

@ghost
Copy link
Author

ghost commented Jan 17, 2023

@yingshaoxo Hello ! I'm waiting for answers from a maintainer, we have to be patient. 😄

@mraleph mraleph requested a review from osa1 January 17, 2023 11:36
@thanhdatvo
Copy link

thanhdatvo commented Jan 26, 2023

@johynpapin It looks like the CI failed. Could you help to update your code so that it could pass the CI checking?
By the way, I did not go through you code yet but I want to ask if there are any signification code update for user?

Thank you,

P/s I'm not a maintainer

@osa1
Copy link
Member

osa1 commented Jan 27, 2023

The CI failure is an existing issue. We fixed it in master branch, if you could merge master or rebase the branch it should be fixed.

(I will be reviewing this soon, sorry for the delay.)

@ghost
Copy link
Author

ghost commented Jan 27, 2023

Hello, I performed a rebase from master 😄
(No need to apologize, it's normal!)

@ghost
Copy link
Author

ghost commented Jan 27, 2023

@thanhdatvo I made sure that no change is visible if the nullable option added to the generator is not used. (Except adding some methods to the GeneratedMessage class.)
If this option is used, then the fields for which it makes sense (messages and optional) are represented with nullable types. The hazzers are kept.
As I asked in my questions in the introduction of this PR, all these choices seem debatable to me and I would love to have feedback on them.

Copy link
Member

@osa1 osa1 left a comment

Choose a reason for hiding this comment

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

This looks great, thanks @johynpapin.

Answering your questions:

Why is ArgumentError.checkNotNull(value, 'value') used in $_setFloat for example, in generated_message.dart?

The library is still used by non-null-safe Dart, so we need to handle the cases where a non-nullable parameter is passed null. We have some tests that run with non-null-safe Dart, see e.g. #791 for some recent work on this.

Is it a good idea to modify generated_message.dart and field_set.dart?

This is fine, but GeneratedMessage members will be usable on messages compiled with or without this feature, so we should make sure they work as expected when called on a message that is compiled without this feature. I added some inline comments on this.

Is it a good idea to add an option to the generator?

Yes!

For tests, is it better to copy the current tests, modifying them to check for nullable types, or is it better to add new tests just for that?

I don't know how to best test this feature yet, I'll need to think more about this. Let me know if you have any ideas.

I think some new tests will be needed as none of the existing tests will be calling the new GeneratedMessage methods.

Is this feature desired in this package?

Yes, I think this is probably the most frequently requested feature.

protoc_plugin/lib/src/protobuf_field.dart Outdated Show resolved Hide resolved
fi, value, 'repeating field (use get + .add())'));
}
if (value == null) {
_clearField(tagNumber);
Copy link
Member

Choose a reason for hiding this comment

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

This will remove required fields from the field set, right? I think that's probably OK (removing required fields is already allowed with clearField), but the documentation says "sets a non-repeated nullable field", and my understanding is only optional fields are nullable.

I think we need two documentation, one for this member with implementation details, one for the GeneratedMessage.setFieldNullable with how the member is supposed to be used. This should say it will just clear the field (same as _clearField). GeneratedMessage.setFieldNullable should clarify what happens when you pass null.

Copy link
Author

Choose a reason for hiding this comment

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

Indeed, I hadn't noticed that!
I'll add some documentation.

Copy link
Author

Choose a reason for hiding this comment

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

I just pushed the changes in the documention, I'm not sure if it's right. 😄

@ghost
Copy link
Author

ghost commented Feb 1, 2023

@osa1 Thank you for all the answers and the review! 🙏 I'll think about the tests.

@bjernie
Copy link

bjernie commented Mar 1, 2023

Any update?

@ghost
Copy link
Author

ghost commented Mar 1, 2023

@bjernie Not really, I've been pretty busy lately. But I intend to finish this! 😉

@craiglabenz
Copy link

How's this going, @johynpapin? Any ways we could be of assistance?

@ghost
Copy link
Author

ghost commented May 2, 2023

Hello @craiglabenz! I've finished the small changes mentioned above, but what's mainly missing are tests. I still don't really know how to properly test these changes, I need to read the ones already written. I'll try to do that before the end of this weekend. 😄

@ghost ghost force-pushed the nullable branch 5 times, most recently from 8dc3cbd to 1009692 Compare May 7, 2023 14:51
@daviddomkar
Copy link

Hi. Is there any update?

@kevmoo
Copy link
Collaborator

kevmoo commented Jul 7, 2023

please rebase this on the latest!

@ghost
Copy link
Author

ghost commented Jul 8, 2023

Hi @kevmoo! First thing I will do tomorrow.

@Arpit1496
Copy link

Arpit1496 commented Jan 16, 2024

Someone is going to have to rebase this on master and we'll go from there...

Done: chitochi#1

Since there were no changes, can we expect it to be merged anytime soon ?

@ghost
Copy link
Author

ghost commented Jan 16, 2024

Hello !
I've just merged the PR, but I've just noticed that it was going towards the master branch and not the nullable branch. 😆
But I just clicked on the GitHub rebase button so I guess it's ok now?

@Arpit1496
Copy link

@kevmoo please check if it is good to go. We won't wanna fall behind master again 😅.

@kevmoo
Copy link
Collaborator

kevmoo commented Jan 17, 2024

I think @osa1 needs to help here.

@Arpit1496
Copy link

@osa1 Please have a look as this is much needed feature for sound null safety.
Also Let us all know how can we help further.

@osa1
Copy link
Member

osa1 commented Jan 19, 2024

I'm on leave right now and won't be able to review this any time soon.

Please have a look as this is much needed feature for sound null safety.

This PR is for convenience only. The library is already sound-null-safe, otherwise you wouldn't be able to use it with Dart 3.

@Arpit1496
Copy link

Agreed. The library is Sound null safe but we have to use checks which is kinda annoying.
Anyway, Let's try to close this whenever you are back. @osa1 If you won't be attending to this issue kindly can you connect to someone who can?

@Arpit1496
Copy link

Arpit1496 commented Jan 25, 2024

@osa1 Any update on this ?

@Arpit1496
Copy link

Any update on this ?

@rostopira
Copy link

@kevmoo while osa1 on the leave, can't you review and merge it finally?
Ignoring someones time and effort for a year is very rude, in my opinion.

@kevmoo
Copy link
Collaborator

kevmoo commented Feb 5, 2024

sorry @rostopira – thanks for your patience

I don't own or maintain this code. I can't add to the maintenance burden without the owner approving!

@Arpit1496
Copy link

Hi everyone, any update on this? @osa1, are you back from leave?

@Arpit1496
Copy link

Do you have any updates yet?
It has been more than a year since the community worked on this. Please find some time to review at least.

@mraleph
Copy link
Member

mraleph commented Feb 20, 2024

We currently don't have any engineering capacity to do a proper review of this PR. @osa1 is an engineer with most context, but he is occupied by more pressing things. Eventually he will get to it, but we are not going to promise any concrete ETA on when this happens.

I understand that it might be rather frustrating to have PR languishing in limbo for a while, but unfortunately we are stretched very thin.

@hiroshihorie
Copy link

I gave up waiting for it to get merged, I just depend on johynpapin:nullable and use it in production at my own risk.

@daviddomkar
Copy link

We currently don't have any engineering capacity to do a proper review of this PR. @osa1 is an engineer with most context, but he is occupied by more pressing things. Eventually he will get to it, but we are not going to promise any concrete ETA on when this happens.

I understand that it might be rather frustrating to have PR languishing in limbo for a while, but unfortunately we are stretched very thin.

I get it but it is sitting here for a year now. Personally, I am waiting for this PR since its inception. Can you at least try to prioritize this please? I don't see anyone relying on this package when there are wait times this long for a simple but much needed feature to get merged.

@ghost
Copy link
Author

ghost commented Mar 20, 2024

Hello everyone!

I just resolved the conflicts, if a rebase is preferred I can do one. 😄

I just wanted to say that I personally don't mind things taking time. I haven't been very reactive on this PR either. 😅

EDIT: By the way, I am in the process of deleting the @johynpapin github account. I will be using @chitochi instead. I hope it will not break too many things in this PR. 😅
EDIT 2: I changed the merge to a rebase.

chitochi and others added 6 commits March 20, 2024 16:15
…tion to hazzers.

Signed-off-by: Chito <chitochi@proton.me>
Signed-off-by: Chito <chitochi@proton.me>
Signed-off-by: Chito <chitochi@proton.me>
note that right now, this test is failing
Signed-off-by: Chito <chitochi@proton.me>
@chitochi chitochi force-pushed the nullable branch 2 times, most recently from f8c18bb to aa7210e Compare March 20, 2024 16:05
@daviddomkar
Copy link

Is there any update?

@daviddomkar
Copy link

Hello, are there any plans to get this merged?

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

Successfully merging this pull request may close these issues.

None yet