Asserting that an entity has a MOC #232

Merged
merged 1 commit into from Feb 5, 2014

3 participants

@notjosh

I'll save the next poor sucker the hassle of diagnosing this the long way.

(For those playing at home, in my case, when GCC_OPTIMIZATION_LEVEL == 0, it worked fine. I was only getting errors in prod builds. Don't be a fool like me, and keep a reference to your MOC so you can, you know, do work within it.)

@robb robb merged commit a4c25f8 into Mantle:master Feb 5, 2014
@robb
Mantle member

Thanks

@jspahrsummers
Mantle member

I think it's legal to have a managed object without a context. Especially for this use, where you just want to parse a MTLModel out of it, it seems reasonable to allow that.

@notjosh

Actually, yeah, you're right. That's a very valid use case. However, without a valid context, the innards of performInContext() won't do a whole lot.

To cater for that use case, you'd have to check for nil and executing the block param directly to get something meaningful back. I wonder if that'd have solved my issue? I'm not sure if that'll have undesired side-effects though.

@robb
Mantle member

Sorry, I'll revert the commit

@notjosh

Actually, given that NSConfinementConcurrencyType is 0, the block will run despite context being nil. So you're right, this is probably better off without the assert for that one use case.

I still think it would make sense to address the problematic use case though. So, maybe instead have an assert that checks -[NSManagedObject isFault] as well as nil context? AFAIK, it will only ever fault if there's persisted data we need to access, in which case it needs a context.

@robb robb added a commit that referenced this pull request Feb 5, 2014
@robb robb Revert "Merge pull request #232 from notjosh/patch-1"
Reverts my premature merge in #232 😓
bacacf5
@jspahrsummers
Mantle member

👍 on isFault.

Let's also add explicit checks for context == nil with performInContext() too. I don't like depending on the value of NSConfinementConcurrencyType.

@notjosh notjosh deleted the notjosh:patch-1 branch Feb 6, 2014
@exsortis exsortis added a commit that referenced this pull request Mar 24, 2014
@exsortis exsortis Merge branch 'master' of https://github.com/MantleFramework/Mantle
# By Justin Spahr-Summers (196) and others
# Via Justin Spahr-Summers (43) and others
* 'master' of https://github.com/MantleFramework/Mantle: (386 commits)
  Fix spec description
  ++xcconfigs
  Catch key path exceptions
  Add test for keypath regression
  Fix typos
  #238: Log errors on encoding/decoding with the key name.
  Added test for initializing the model using a JSONDictionary with NSNull.null as value
  Fix backwards compatibility for keys with value null
  Minor style fixes
  Avoid sending exception for an invalid keypath, instead returning an error
  Revert "Merge pull request #232 from notjosh/patch-1"
  Asserting that an entity has a MOC
  Revert "Add podspec file"
  Fix a crash when an invalid keypath is used
  Remove unnecessary error code
  Remove static qualifier from error codes
  ++xcconfigs
  Fixed 'guarantee' typo
  MTLManagedObjectAdapter: Fixes an issue with validate for insert
  MTLManagedObjectAdapter: Add tests for validating values
  ...

Conflicts:
	Mantle.xcodeproj/project.pbxproj
	Mantle.xcodeproj/xcshareddata/xcschemes/Mantle-iOS.xcscheme
	Mantle.xcodeproj/xcshareddata/xcschemes/Mantle.xcscheme
	Mantle/CGGeometry+MTLConvenienceAdditions.h
	libextobjc
8df8de5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment