-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add nullability annotations to WPAccount #24328
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
Conversation
Generated by 🚫 Danger |
|
|
||
| @property (nonatomic, strong, nullable) NSNumber *userID; | ||
| @property (nonatomic, strong, nullable) NSString *avatarURL; | ||
| @property (nonatomic, copy, nonnull) NSString *username; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit) nonnull is redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure username is nonnull?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| get { | ||
| guard let api = objc_getAssociatedObject(self, &apiAssociatedKey) as? WordPressComRestApi else { | ||
| guard authToken.isEmpty else { | ||
| if let authToken, !authToken.isEmpty { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also changing these lines here #24327 👀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just saw your PR. I can resolve the conflicts once yours is merged. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My PR is missing the nullability check, so this change will be needed.
| @objc | ||
| var hasBlogs: Bool { | ||
| return !blogs.isEmpty | ||
| return blogs?.isEmpty == false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(nit) Is there any way to make blogs in WPAccount nonnull for convenience?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At runtime, it probably won't be null. Core Data should return an empty list if there is no Blog instance associated with this account. However, considering an "Optional" property in the relationship configuration, I feel it is safer to declare it nullable.
|
| App Name | WordPress Alpha |
|
| Configuration | Release-Alpha | |
| Build Number | pr24328-d9f9d89 | |
| Version | 25.8 | |
| Bundle ID | org.wordpress.alpha | |
| Commit | d9f9d89 | |
| App Center Build | WPiOS - One-Offs #11860 |
|
| App Name | Jetpack Alpha |
|
| Configuration | Release-Alpha | |
| Build Number | pr24328-d9f9d89 | |
| Version | 25.8 | |
| Bundle ID | com.jetpack.alpha | |
| Commit | d9f9d89 | |
| App Center Build | jetpack-installable-builds #10883 |
|
| App Name | Jetpack | |
| Configuration | Release-Alpha | |
| Build Number | 27020 | |
| Version | PR #24328 | |
| Bundle ID | com.jetpack.alpha | |
| Commit | ddc2105 | |
| Installation URL | 3nr1nu8s78mbg |
|
| App Name | WordPress | |
| Configuration | Release-Alpha | |
| Build Number | 27020 | |
| Version | PR #24328 | |
| Bundle ID | org.wordpress.alpha | |
| Commit | ddc2105 | |
| Installation URL | 4s4g51ihlfoo8 |
| } else if let account = try WPAccount.lookupDefaultWordPressComAccount(in: context) { | ||
| siteID = account.primaryBlogID | ||
| } else if let account = try WPAccount.lookupDefaultWordPressComAccount(in: context), let primaryBlogID = account.primaryBlogID { | ||
| return nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a function change. Previous:
siteID = account.primaryBlogID
```There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Fixed in a185c04
|
|
||
| @property (nonatomic, strong, nullable) NSNumber *userID; | ||
| @property (nonatomic, strong, nullable) NSString *avatarURL; | ||
| @property (nonatomic, copy, nonnull) NSString *username; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure username is nonnull?
| if let account = blog.account { | ||
| self.init(baseUrl: url, type: .dotCom(authToken: account.authToken)) | ||
| if let account = blog.account, let authToken = account.authToken { | ||
| self.init(baseUrl: url, type: .dotCom(authToken: authToken)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as a blog has an associated WP.com, it should be using a .dotCom client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All WPAccount instances should have an authToken because they are created after signing into WP.com. We can change the WordPressClient to make it support anonymous API requests, but I don't think that's necessary because it won't be used to make anonymous API calls?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that if account.authToken is nil, it will now fall into the else with .selfHosted, which is the logic change. Should it throw an error instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah of course. I have addressed the issue in 8af7561.
|
I'm going to merge it if you don't mind – need some of this code in another branch. |
|
@kean 👍 Thanks! |



This PR should fix the crash in #24320
The crash happens at
authToken.isEmpty.authTokencan be nil, but the Objective-C API didn't have nullabilty annotation which makes it an IUO property.To test:
Regression Notes
Potential unintended areas of impact
What I did to test those areas of impact (or what existing automated tests I relied on)
What automated tests I added (or what prevented me from doing so)
PR submission checklist:
RELEASE-NOTES.txtif necessary.Testing checklist: